Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

MathAndSystem.cpp

Go to the documentation of this file.
00001 
00002 // MathCore = a WYSIWYG equation editor + a powerful math engine     //
00003 // Copyright (C) 2003 by Francesco Montorsi                          //
00004 //                                                                   //
00005 // This library is free software; you can redistribute it and/or     //
00006 // modify it under the terms of the GNU Lesser General Public        //
00007 // License as published by the Free Software Foundation; either      //
00008 // version 2.1 of the License, or (at your option) any later         //
00009 // version.                                                          //
00010 //                                                                   //
00011 // This library is distributed in the hope that it will be useful,   //
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of    //
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      //
00014 // GNU Lesser General Public License for more details.               //
00015 //                                                                   //
00016 // You should have received a copy of the GNU Lesser General Public  //
00017 // License along with this program; if not, write to the Free        //
00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,   //
00019 // MA 02111-1307, USA.                                               //
00020 //                                                                   //
00021 // For any comment, suggestion or feature request, please contact    //
00022 // the administrator of the project at frm@users.sourceforge.net     //
00023 //                                                                   //
00030 
00031 
00032 
00033 // optimization for GCC compiler
00034 #ifdef __GNUG__
00035 #pragma implementation "MathAndSystem.h"
00036 #endif
00037 
00038 // includes
00039 #include "mc/mcprec.h"
00040 #ifdef __BORLANDC__
00041     #pragma hdrstop
00042 #endif
00043 
00044 #ifndef mcPRECOMP
00045     #include <wx/dcscreen.h>
00046  #include "mc/MathCore.h"
00047  #include "mc/Text.h"
00048  #include "mc/MathLine.h"
00049  #include "mc/MathSystem.h"
00050  #include "mc/MathAndSystem.h"
00051 #endif
00052 
00053 
00054 // setup customizable variables
00055 int mcMathAndSystemHelpers::sgui_nSpaceAboveBelow = 4;
00056 int mcMathAndSystemHelpers::sgui_nSpaceLeftRight = 4;
00057 int mcMathAndSystemHelpers::sgui_nSpaceBetween = 10;
00058 bool mcMathAndSystemHelpers::sgui_bHorizOrientation = FALSE;
00059 mcMathAndSystemRenderMode mcMathAndSystemHelpers::sgui_nRenderMode = mcMASRM_DRAW_AND_SYMBOLS;
00060 
00061 
00062 
00063 
00064 // ------------------------
00065 // mcMATHANDSYSTEMDATA
00066 // ------------------------
00067 
00068 #ifdef __MCDEBUG__
00069 
00070 wxString mcMathAndSystemHelpers::data_Debug(long flags) const
00071 {
00072  wxString indent = wxString(wxT(' '), mcMathCore::Get()->m_nIndentationStep);
00073  wxString str = data_GetDebugName() + wxT(" [\n\n");
00074 
00075  for (int i=0; i<data_GetCount(); i++) {
00076 
00077   if (i) str+=wxT("\n");
00078   str += wxString::Format(wxT("%s----->>> ELEMENT %d <<<-----\n"), indent.c_str(), i);
00079   str += data_Get(i).data_GetDebug(mcMathCore::Get()->m_nIndentationStep, flags);
00080   str += wxString::Format(wxT("%s----->>> ELEMENT %d <<<-----\n"), indent.c_str(), i);
00081   str += wxT("\n");
00082  }
00083 
00084  str += data_GetDebugName() + wxT(" ]");
00085  return str;
00086 }
00087 
00088 #endif
00089 
00090 void mcMathAndSystemHelpers::data_SetFilter(const mcFilter *p, int n)
00091 {
00092  if (n <= -1) {
00093 
00094   // set the filter for all the elements
00095   for (int i=0; i < data_GetCount(); i++)
00096    data_GetLine(i).data_SetFilter(p);
00097   return;
00098  }
00099 
00100  data_GetLine(n).data_SetFilter(p);
00101 }
00102 
00103 
00104 
00105 
00106 
00107 // ------------------------
00108 // mcMATHANDSYSTEMGUI
00109 // ------------------------
00110 
00111 void mcMathAndSystemHelpers::gui_RecalcSymbolSize()
00112 {
00113  wxScreenDC dc;
00114  gui_SelectStyle(dc);
00115 
00116  switch (sgui_nRenderMode) {
00117  case mcMASRM_DRAW_AND_TEXT:
00118   mgui_szSymbol = gui_GetSizeOf(&dc, wxT("AND"));
00119   break;
00120 
00121  case mcMASRM_DRAW_AND_SYMBOLS:
00122   mgui_szSymbol = gui_GetSizeOf(&dc, wxT("^"));
00123   break;
00124 
00125  case mcMASRM_DRAW_CURLY_BRACKET:
00126   break;
00127  }
00128 }
00129 
00130 void mcMathAndSystemHelpers::gui_DrawSystemSymbols(wxDC &dc, int x, int y, long flags) const
00131 {
00132  // first of all, select the style...
00133  gui_SelectStyle(dc);
00134  dc.SetBackgroundMode(wxTRANSPARENT);
00135 
00136  // do we have to draw the system symbol ?
00137  switch (sgui_nRenderMode) {
00138  case mcMASRM_DRAW_AND_TEXT:
00139   {
00140    // draw all the connector symbols
00141    for (int i=0; i<data_GetCount()-1; i++)
00142     dc.DrawText(wxT("AND"), x+gui_GetXOfSymbol(i), y+gui_GetYOfSymbol(i));
00143   }
00144   break;
00145 
00146  case mcMASRM_DRAW_AND_SYMBOLS:
00147   {
00148    // draw all the connector symbols
00149    for (int i=0; i<data_GetCount()-1; i++)
00150     dc.DrawText(wxT("^"), x+gui_GetXOfSymbol(i), y+gui_GetYOfSymbol(i));
00151   }
00152   break;
00153   
00154  case mcMASRM_DRAW_CURLY_BRACKET:
00155   dc.SetFont(mgui_fLastFont);
00156   dc.DrawText(wxT("{"), x, y);
00157   break;
00158  }
00159 }
00160 
00161 bool mcMathAndSystemHelpers::gui_isIDChanged() const
00162 {
00163  // check if something changed...
00164  if (mgui_nCurrentActive == mgui_nLastActive) {
00165 
00166   // if the last active line as still the same active element,
00167   // then the ID has not changed...
00168   if (mgui_nCurrentActive != -1)
00169    return data_GetLine(mgui_nCurrentActive).gui_isIDChanged();
00170   return FALSE;
00171  }
00172  return TRUE;
00173 }
00174 
00175 int mcMathAndSystemHelpers::gui_GetActiveElemID() const
00176 {
00177  if (mgui_nCurrentActive != -1) 
00178   return data_GetLine(mgui_nCurrentActive).gui_GetActiveElemID(); 
00179 
00180  return mcDRW_NOACTIVEELEM;
00181 }
00182 
00183 mcElement mcMathAndSystemHelpers::gui_GetSelection() const
00184 {
00185  for (int i=0; i<data_GetCount(); i++) {
00186   if (data_Get(i).gui_isSelected()) {
00187 
00188    // we've found our line containing the selection
00189    mcMathAndSystem sys;
00190    sys.hlp()->data_Add(new mcMathLine(data_Get(i).gui_GetSelection()));
00191    return sys;
00192   }
00193  }
00194 
00195  return mcEmptySystem;
00196 }
00197 
00198 
00199 
00200 
00201 // ------------------------
00202 // mcMATHANDSYSTEMIO
00203 // ------------------------
00204 
00205 bool mcMathAndSystemHelpers::io_ImportToken(const wxString &str, wxString *perr)
00206 {
00207  data_AddEmptyLine();
00208  
00209  // process token here
00210  if (!data_GetLastLine().io_ImportInlinedExpr(str, NULL, *perr))
00211   return FALSE;
00212  return TRUE;
00213 }
00214 
00215 
00216 
00217 
00218 // ------------------------
00219 // mcMATHANDSYSTEMMATH
00220 // ------------------------
00221 
00222 mcMathSystemType mcMathAndSystemHelpers::math_GetMathSystemType() const
00223 {
00224  bool alleq = TRUE, allineq = TRUE;
00225 
00226  // check if all the lines contains equations or inequalities
00227  for (int i=0; i < data_GetCount(); i++) {
00228 
00229   mcMathMngType type = data_GetLine(i).math_GetMathMngType();
00230   alleq &= (type == mcMMT_EQUATION);
00231   allineq &= (type != mcMMT_EQUATION && type != mcMMT_EXPRESSION);
00232  }
00233 
00234  // do we contain only an expression ?
00235  if (data_GetCount() == 1 &&
00236   data_GetLine(0).math_GetMathMngType() == mcMMT_EXPRESSION)
00237   return mcMSTL1_EXPRESSION;
00238 
00239  if (alleq) return mcMSTL1_EQUATIONS;
00240  if (allineq) return mcMSTL1_INEQUALITIES;
00241 
00242  // this is the last option...
00243  return mcMSTL1_MIXED;
00244 }
00245 
00246 void mcMathAndSystemHelpers::math_Merge(const mcMathAndSystem &arr1,
00247           const mcMathAndSystem &arr2)
00248 {
00249  data_Clear();
00250 
00251  // copy the elements of the first array
00252  data_DeepCopy(arr1.chlp());
00253  for (int i=0; i<arr2.data_GetCount(); i++)
00254   data_Add(new mcMathLine(arr2.data_GetLine(i)));
00255 
00256  mcMATHLOG(wxT("mcMathAndSystemHelpers::math_Merge - merged [%s] and [%s] into this: [%s]"),
00257     mcTXT(arr1), mcTXT(arr2), mcTXTTHIS);
00258 }
00259 
00260 


Documentation generated with Doxygen on Sun Feb 6 17:10:47 2005
Visit MathStudio home page for more info

[ Top ]