Bug 117774 - Calculator doesn't do nothing
Summary: Calculator doesn't do nothing
Status: RESOLVED FIXED
Alias: None
Product: kalzium
Classification: Applications
Component: Calculator (show other bugs)
Version: unspecified
Platform: Slackware Linux
: NOR normal
Target Milestone: ---
Assignee: Kalzium Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-06 08:56 UTC by Vito De Tullio
Modified: 2005-12-30 10:54 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch for this bug (5.77 KB, patch)
2005-12-29 15:05 UTC, Carsten Niehaus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vito De Tullio 2005-12-06 08:56:09 UTC
Version:            (using KDE KDE 3.5.0)
Installed from:    Slackware Packages
OS:                Linux

If I try to calculate anything (from 2+2 to aH2O + bCO2 -> cH2CO3) I got nothing.
Nor an error, nor the window I see in the help... I didn't see anything neither on the STDOUT!
Comment 1 Davide Ferrari 2005-12-06 11:49:44 UTC
I can reproduce it on KDE 3.5.0 compiled from tarballs on Gentoo (so Kalzium 1.4.2)
There is no output at all, neither an error box. It seems that the Calculate button simply does nothing.
Comment 2 Pino Toscano 2005-12-06 13:26:20 UTC
> If I try to calculate anything (from 2+2 to aH2O + bCO2 -> cH2CO3)


Wait. What are you trying to calculate, and where?
Kalzium has two types of calculators:
- one of them is in the sidebar and calculates the weight of a molecule (like 
C6H12O6)
- the other one (reachable from Tools->Equation Solver) solves equation like 
the last one you wrote (aH2O + bCO2 -> cH2CO3). And this calculator solves 
prefectly this eqations, giving a=1, b=1 and c=1 as correct result.

So, I don't see any issue; otherwise, could you please be more precise?
Comment 3 Vito De Tullio 2005-12-07 08:54:51 UTC
Well...
I can see just *ONE* calculator! (the one in the sidebar)
In Tools menu I can see just (from italian, re-translated to english) "data diagram" and "glossary". No "equation solver" or something similar! This is strange!

As corncerns the sidebar calculator, if I enter just a molecule (like H2O or your C6H12O6) it runs smootly, but if I enter something else it does nothing. Coud be useful if kalzium pop up a "error" window, or something similar.
Comment 4 Carsten Niehaus 2005-12-07 09:39:38 UTC
>I can see just *ONE* calculator! (the one in the sidebar) 
>In Tools menu I can see just (from italian, re-translated to english) "data >diagram" and "glossary". No "equation solver" or something similar! This is >strange!

No, that is not strange. That is a "bug" in slackware: The new Kalzium is offering the new calculator only if on compiletime (!) OCamls and libfacile if found. You are using a binary version of Kalzium so you did nothing wrong. Please tell the Kalzium-packager of slackware that he needs to have ocaml and libfacile installed when configuring Kalzium. You can read this up in the README.packagers in Kalzium. Again: The two packages are *not* needed on runtime!
 
>As corncerns the sidebar calculator, if I enter just a molecule (like H2O or >your C6H12O6) it runs smootly, but if I enter something else it does nothing. >Coud be useful if kalzium pop up a "error" window, or something similar.

What is "something" else? Please tell us exactly what is not working (which strings). You can only enter the symbols of existing elements.
Comment 5 Vito De Tullio 2005-12-07 12:43:11 UTC
My only problem in the molecular calculator is that it pass "silently" errors, and don'd do anything if I enter wrong values such as "H+H" or, even worster, show "partially right" values if I enter "H2ZO" (it rekognize the "H2" part, and it show it's just H_2).
Comment 6 Pino Toscano 2005-12-07 19:50:50 UTC
> if I enter wrong values such as "H+H"


Kalzium calculator is more a molecular weight measure than a really 
calculator, so that expression is not valid.

> show "partially right" values if I enter "H2ZO" (it rekognize the "H2" part, 
> and it show it's just H_2).


Ok, that one is a fault, and should be fixed, along with a notofication of the 
failed molecule parsing.
Comment 7 cniehaus 2005-12-29 13:59:06 UTC
Hi

In Kalzium you can calculate the molecular weight of a molecule. 

Calculate "CO2Of". Of course there is no element "f". The result is (on the 
shell)

kalzium: Found element C
kalzium: Found element O
kalzium: Weight of term = 12.0107
kalzium: [Element* MoleculeParser::lookupElement(const QString&)] no such 
element: Of
kalzium: Weight of term = 31.9988
kalzium: Mass of CO2Of = 44.0095

The GUI presents 44.0095 as the result to the user. No errormessage. This is 
wrong for two reasons: 
1 - As the input was invalid there should be no result
2 - *If* we show a result it be neglect the "f" and display "60.0089" as a 
result because the would be correct for "CO2O".


Now calculate "CO2O":

kalzium: Found element C
kalzium: Found element O
kalzium: Weight of term = 12.0107
kalzium: Found element O
kalzium: Weight of term = 31.9988
kalzium: Weight of term = 15.9994
kalzium: Mass of CO2O = 60.0089

The result is correct and presented as 60.0089. 

Solution: Display a "Invalid input"-error.

Question 1: Is this the same as BUG 117774?
Question 2 (for the kde-i18n-folks): Would it be ok to display the new 
errormessage? I would introduce the new string today. I am not sure if this 
bugfix+new message would be covered by the current message-policy...

Carsten
Comment 8 Carsten Niehaus 2005-12-29 15:05:29 UTC
Created attachment 14063 [details]
Patch for this bug
Comment 9 cniehaus 2005-12-29 15:37:45 UTC
Am Donnerstag, 29. Dezember 2005 15:05 schrieb Carsten Niehaus:
[bugs.kde.org quoted mail]

> ------- Additional Comments From cniehaus kde org  2005-12-29 15:05 -------
> Created an attachment (id=14063)
>  --> (http://bugs.kde.org/attachment.cgi?id=14063&action=view)
> Patch for this bug



This patch fixes both bugs: 

1: H2f       <--  recoqnized as invalid input
2: Invalid input will be displayed as such

Ok to commit? This introduces one new string (i18n("Invalid input")

Carsten
Comment 10 cniehaus 2005-12-30 10:54:46 UTC
SVN commit 492531 by cniehaus:

This fixes bug #117774 The calculator has two issues. First, it didn't
tell the user when the string was invalid (eg H2Ojdfkjd). Second,
it didn't stop calculating in some cases (H2g produces a different
error than H2Og, only the first stopped the calculation). With this commit
I am introducing a new string "Invalid input" which is displayed 
when the parser notices an error.
CCMAIL:kalzium@kde.org
BUG:117774


 M  +47 -43    molcalcwidget.cpp  
 M  +1 -0      molcalcwidget.h  
 M  +13 -6     moleculeparser.cpp  
 M  +3 -2      moleculeparser.h  


--- branches/KDE/3.5/kdeedu/kalzium/src/molcalcwidget.cpp #492530:492531
@@ -68,41 +68,53 @@
 
 void MolcalcWidget::updateUI()
 {
-	QString str;
+	if ( m_validInput ){
 
-	// The complexString stores the whole molecule like this:
-	// 1 Seaborgium. Cumulative Mass: 263.119 u (39.2564 %)
-	QString complexString;
-	
-	// Create the list of elements making up the molecule
-	ElementCountMap::Iterator  it    = m_elementMap.begin();
-	ElementCountMap::Iterator  itEnd = m_elementMap.end();
-	for ( ; it != itEnd; ++it ) {
-		// Update the resultLabel
-		str += i18n( "For example: \"1 Carbon\" or \"3 Oxygen\"", "%1 %2\n" )
-		  .arg( (*it)->count() )
-		  .arg( (*it)->element()->elname() );
+		QString str;
 
-		complexString
-		  += i18n( "For example: 1 Seaborgium. Cumulative Mass: 263.119 u (39.25%)",
-				   "%1 %2. Cumulative Mass: %3 u (%4%)\n" )
-		  .arg( (*it)->count() )
-		  .arg( (*it)->element()->elname() )
-		  .arg( (*it)->count() * (*it)->element()->mass() )
-		  .arg( KalziumUtils::strippedValue( (( (*it)->count() * (*it)->element()->mass() )
-											  / m_mass ) * 100 ) );
+		// The complexString stores the whole molecule like this:
+		// 1 Seaborgium. Cumulative Mass: 263.119 u (39.2564 %)
+		QString complexString;
+
+		// Create the list of elements making up the molecule
+		ElementCountMap::Iterator  it    = m_elementMap.begin();
+		ElementCountMap::Iterator  itEnd = m_elementMap.end();
+		for ( ; it != itEnd; ++it ) {
+			// Update the resultLabel
+			str += i18n( "For example: \"1 Carbon\" or \"3 Oxygen\"", "%1 %2\n" )
+				.arg( (*it)->count() )
+				.arg( (*it)->element()->elname() );
+
+			complexString
+				+= i18n( "For example: 1 Seaborgium. Cumulative Mass: 263.119 u (39.25%)",
+						"%1 %2. Cumulative Mass: %3 u (%4%)\n" )
+				.arg( (*it)->count() )
+				.arg( (*it)->element()->elname() )
+				.arg( (*it)->count() * (*it)->element()->mass() )
+				.arg( KalziumUtils::strippedValue( (( (*it)->count() * (*it)->element()->mass() )
+								/ m_mass ) * 100 ) );
+		}
+		resultLabel->setText( str );
+
+		// The composition
+		resultComposition->setText( compositionString(m_elementMap) );
+
+		// The mass
+		resultMass->setText( i18n( "Molecular mass: %1 u" ).arg( m_mass ) );
+
+		QToolTip::add( resultMass,        complexString );
+		QToolTip::add( resultComposition, complexString );
+		QToolTip::add( resultLabel,       complexString );
 	}
-	resultLabel->setText( str );
-	
-	// The composition
-	resultComposition->setText( compositionString(m_elementMap) );
-	
-	// The mass
-	resultMass->setText( i18n( "Molecular mass: %1 u" ).arg( m_mass ) );
-	
-	QToolTip::add( resultMass,        complexString );
-	QToolTip::add( resultComposition, complexString );
-	QToolTip::add( resultLabel,       complexString );
+	else{//the input was invalid, so tell this the user
+		resultComposition->setText( i18n( "Invalid input" ) );
+		resultLabel->setText( QString() );
+		resultMass->setText( QString() );
+		
+		QToolTip::add( resultMass,        i18n( "Invalid input" ) );
+		QToolTip::add( resultComposition, i18n( "Invalid input" ) );
+		QToolTip::add( resultLabel,       i18n( "Invalid input" ) );
+	}
 }
 
 
@@ -132,17 +144,9 @@
 
 	// Parse the molecule, and at the same time calculate the total
 	// mass, and the composition of it.
-	bool parseOk = m_parser.weight(molecule, &m_mass, &m_elementMap);
-
-	if (parseOk) {
-		kdDebug() << "Mass of " << molecule << " = " << m_mass << endl;
-
-		updateUI();
-	}
-	else {
-		// FIXME: Do something better here.
-		kdDebug() << "Parse error" << endl;
-	}
+	m_validInput = m_parser.weight(molecule, &m_mass, &m_elementMap);
+	
+	updateUI();
 }
 
 
--- branches/KDE/3.5/kdeedu/kalzium/src/molcalcwidget.h #492530:492531
@@ -72,6 +72,7 @@
 		MoleculeParser   m_parser;
 		
 		double           m_mass;
+		bool 			 m_validInput;
 		ElementCountMap  m_elementMap;
 };
 
--- branches/KDE/3.5/kdeedu/kalzium/src/moleculeparser.cpp #492530:492531
@@ -124,8 +124,9 @@
 					   double          *_resultMass,
 					   ElementCountMap *_resultMap)
 {
-    // Clear the result variables.
+    // Clear the result variables and set m_error to false
     _resultMap->clear();
+	m_error = false;
     *_resultMass = 0.0;
 
 	// Initialize the parsing process, and parse te molecule.
@@ -135,6 +136,9 @@
     if (nextToken() != -1)
 		return false;
 
+	if ( m_error )//there was an error in the input...
+		return false;
+
     return true;
 }
 
@@ -286,12 +290,15 @@
     const EList::ConstIterator  end = elementList.constEnd();
 
     for (; it != end; ++it) {
-	if ( (*it)->symbol() == _name ) {
-	    kdDebug() << "Found element " << _name << endl;
-	    return *it;
-	}
+		if ( (*it)->symbol() == _name ) {
+			kdDebug() << "Found element " << _name << endl;
+			return *it;
+		}
     }
 
-    kdDebug() << k_funcinfo << "no such element: " << _name << endl;
+	//if there is an error make m_error true.
+	m_error = true;
+
+    kdDebug() << k_funcinfo << "no such element, parsing error!: " << _name << endl;
     return NULL;
 }
--- branches/KDE/3.5/kdeedu/kalzium/src/moleculeparser.h #492530:492531
@@ -103,8 +103,6 @@
     bool  weight(QString         _moleculeString,
 				 double          *_resultMass,
 				 ElementCountMap *_resultMap);
-    //QMap<Element*, int>   elementMap();
-    //QValueList<Element*>  elementList();
 
  private:
     // Helper functions
@@ -117,6 +115,9 @@
 
     QMap<Element*, int> m_elementMap;
 
+	//if this booloean is "true" the parser found an error
+	bool m_error;
+
 protected:
 
     /**