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

MathOrSystem.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 "MathOrSystem.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/MathOrSystem.h"
00051 #endif
00052 
00053 
00054 // customizable variables
00055 int mcMathOrSystemHelpers::sgui_nSpaceAboveBelow = 5;
00056 int mcMathOrSystemHelpers::sgui_nSpaceLeftRight = 5;
00057 int mcMathOrSystemHelpers::sgui_nSpaceBetween = 10;
00058 bool mcMathOrSystemHelpers::sgui_bHorizOrientation = TRUE;
00059 bool mcMathOrSystemHelpers::sgui_bDrawOrLabels = FALSE;
00060 
00061 
00062 
00063 // ------------------------
00064 // mcMATHORSYSTEMDATA
00065 // ------------------------
00066 
00067 #ifdef __MCDEBUG__
00068 
00069 wxString mcMathOrSystemHelpers::data_Debug(long flags) const
00070 {
00071  wxString str, type = data_GetDescString();
00072 
00073  // create a string containing the debug info for all the
00074  // equations\inequalities contained
00075  str.Alloc(2048);
00076  str = wxT("\n\n  ::::: mcMathOrSystem\n");
00077  str += wxT("  ::::: Classified as '") + type + wxT("'\n");
00078  str += wxT("  ") + wxString(wxT('-'), 75)+ wxT("\n\n");
00079  for (int i=0; i < data_GetCount(); i++) {  
00080   if (i) str += wxT("\n\n\n");
00081   //str += wxString::Format("EQUATION\\INEQUALITY #%d\n", i);
00082   str += data_Get(i).data_GetDebug(mcMathCore::Get()->m_nIndentationStep, flags);
00083     /*Indent(data_Get(i).data_GetDebug(0, flags), 
00084     mcMathCore::Get()->m_nIndentationStep);*/
00085  }
00086 
00087  return str;
00088 }
00089 
00090 wxString mcMathOrSystemHelpers::data_GetMemoryInfoStr() const
00091 {
00092  wxString str;
00093 
00094  str = wxT("\n\n::::::::: MathCore class sizes:\n") + 
00095     mcElementHelpers::data_GetGlobalMemoryInfo(); 
00096 
00097 #ifdef mcENABLE_COW_DEBUG
00098  str += wxString::Format(wxT("\n\nMaximum shared instances of a ")
00099   wxT("mcElement-derived class: %d"), mcMathCore::Get()->m_nMaxSharing);
00100  str += wxString::Format(wxT("\n\nMaximum shared instances of a ")
00101   wxT("mcValue-derived class: %d"), mcValue::m_nMaxValueSharing);
00102 #endif
00103 
00104  return str;
00105 }
00106 
00107 #endif  // __MCDEBUG__
00108 
00109 void mcMathOrSystemHelpers::data_Delete(int n)
00110 { delete ((mcMathAndSystem*)data_GetItem(n)); }
00111 
00112 mcAbstractItem *mcMathOrSystemHelpers::data_GetCopyOf(int n) const
00113 { return new mcMathAndSystem(data_GetSys(n)); }
00114 
00115 wxString mcMathOrSystemHelpers::data_GetDescString() const
00116 {
00117  // create the classification string
00118  return math_GetMathType().io_GetDescString() + 
00119    math_GetMathSystemType().io_GetDescString(data_GetLineCount());
00120 }
00121 
00122 int mcMathOrSystemHelpers::data_GetLineCount() const
00123 {
00124  int total=0;
00125 
00126  // get the total number of lines
00127  for (int i=0; i<data_GetCount(); i++)
00128   total+=data_GetSys(i).data_GetCount();
00129  return total;
00130 }
00131 
00132 void mcMathOrSystemHelpers::data_AddLineToLastAndSystem(mcMathLine *toadd)
00133 {
00134  if (data_GetCount() == 0) 
00135   data_AddLineToNewAndSystem(toadd); 
00136  else
00137   data_GetLastSys().data_AddLine(toadd); 
00138 }
00139 
00140 void mcMathOrSystemHelpers::data_AddLineToNewAndSystem(mcMathLine *toadd)
00141 {
00142  mcMathAndSystem *s=new mcMathAndSystem();
00143 
00144  // adds the line
00145  s->data_AddLine(toadd);
00146  data_AddSys(s);
00147 }
00148 
00149 void mcMathOrSystemHelpers::data_SetFilter(const mcFilter *p, int n)
00150 {
00151  if (n <= -1) {
00152 
00153   // set the filter for all the elements
00154   for (int i=0; i < data_GetCount(); i++)
00155    data_GetSys(i).data_SetFilter(p, -1);
00156   return;
00157  }
00158 
00159  data_GetSys(n).data_SetFilter(p, -1);
00160 }
00161 
00162 
00163 
00164 
00165 
00166 // ------------------------
00167 // mcMATHORSYSTEMGUI
00168 // ------------------------
00169 
00170 void mcMathOrSystemHelpers::gui_RecalcSymbolSize()
00171 {
00172  wxScreenDC dc;
00173  gui_SelectStyle(dc);
00174 
00175  if (sgui_bDrawOrLabels)
00176   mgui_szSymbol = gui_GetSizeOf(&dc, wxT("OR"));
00177  else
00178   mgui_szSymbol = gui_GetSizeOf(&dc, wxT("v"));
00179 }
00180 
00181 void mcMathOrSystemHelpers::gui_DrawSystemSymbols(wxDC &dc, int x, int y, long flags) const
00182 {
00183  gui_SelectStyle(dc);
00184  dc.SetBackgroundMode(wxTRANSPARENT);
00185 
00186  // draw all the connector symbols
00187  for (int i=0; i<data_GetCount()-1; i++)
00188   if (sgui_bDrawOrLabels)
00189    dc.DrawText(wxT("OR"), x+gui_GetXOfSymbol(i), y+gui_GetYOfSymbol(i));
00190   else
00191    dc.DrawText(wxT("v"), x+gui_GetXOfSymbol(i), y+gui_GetYOfSymbol(i));
00192 }
00193 
00194 int mcMathOrSystemHelpers::gui_GetActiveElemID() const
00195 {
00196  if (mgui_nCurrentActive != -1) 
00197   return data_GetSys(mgui_nCurrentActive).gui_GetActiveElemID(); 
00198 
00199  return mcDRW_NOACTIVEELEM;
00200 }
00201 
00202 mcElement mcMathOrSystemHelpers::gui_GetSelection() const
00203 {
00204  for (int i=0; i<data_GetCount(); i++) {
00205   if (data_Get(i).gui_isSelected()) {
00206 
00207    // we've found our line containing the selection
00208    mcMathOrSystem sys;
00209 
00210    // FIXME:
00211    sys.hlp()->data_Add(new mcMathAndSystem(data_Get(i).gui_GetSelection()));
00212    return sys;
00213   }
00214  }
00215 
00216  return mcEmptySystem;
00217 }
00218 
00219 bool mcMathOrSystemHelpers::gui_isIDChanged() const
00220 {
00221  // check if something changed...
00222  if (mgui_nCurrentActive == mgui_nLastActive) {
00223 
00224   // if the last active line as still the same active element,
00225   // then the ID has not changed...
00226   if (mgui_nCurrentActive != -1)
00227    return data_GetSys(mgui_nCurrentActive).gui_isIDChanged();
00228   return FALSE;
00229  }
00230  return TRUE;
00231 }
00232 
00233 mcMathLine &mcMathOrSystemHelpers::gui_GetFocusLine()
00234 {
00235  mcMathAndSystem &sel = gui_GetFocusSys();
00236  if (sel == mcEmptyElement) return mcEmptyLine;
00237 
00238  // return the line focused inside the current focused mcMathAndSystem
00239  return sel.gui_GetFocusLine();
00240 }
00241 
00242 const mcMathLine &mcMathOrSystemHelpers::gui_GetFocusLine() const
00243 {
00244  const mcMathAndSystem &sel = gui_GetFocusSys();
00245  if (sel == mcEmptyElement) return mcEmptyLine;
00246 
00247  // return the line focused inside the current focused mcMathAndSystem
00248  return sel.gui_GetFocusLine();
00249 }
00250 
00251 void mcMathOrSystemHelpers::gui_AddEmptyLineToLastAndSystem()
00252 {
00253  mcMathLine *toadd = new mcMathLine();
00254  toadd->data_GetLeftMem().gui_AddNewEmptyMonomial();
00255 
00256  data_AddLineToLastAndSystem(toadd);
00257 }
00258 
00259 void mcMathOrSystemHelpers::gui_AddEmptyLineToNewAndSystem()
00260 {
00261  mcMathLine *toadd = new mcMathLine();
00262  toadd->data_GetLeftMem().gui_AddNewEmptyMonomial();
00263 
00264  data_AddLineToNewAndSystem(toadd);
00265 }
00266 
00267 
00268 
00269 
00270 
00271 // ------------------------
00272 // mcMATHORSYSTEMIO
00273 // ------------------------
00274 
00275 bool mcMathOrSystemHelpers::io_ImportToken(const wxString &str, wxString *perr)
00276 {
00277  int n;
00278  data_Add(new mcMathAndSystem());
00279  
00280  // process token here  
00281  if (!data_GetLast().io_ImportInlinedExpr(str, &n, *perr))
00282   return FALSE;
00283  return TRUE;
00284 }
00285 
00286 
00287 
00288 // ------------------------
00289 // mcMATHORSYSTEMMATH
00290 // ------------------------
00291 
00292 void mcMathOrSystemHelpers::math_AndMerge(const mcMathOrSystem &arr1,
00293             const mcMathOrSystem &arr2)
00294 {
00295  mcMATHLOG(wxT("mcMathOrSystemHelpers::math_AndMerge - merging [%s] with [%s]"), 
00296     mcTXT(arr1), mcTXT(arr2));
00297  
00298  data_Clear();
00299  for (int i=0; i<arr1.data_GetCount(); i++) {
00300   for (int j=0; j<arr2.data_GetCount(); j++) {
00301 
00302    mcMathAndSystem *res = new mcMathAndSystem();
00303    res->math_Merge(arr1.data_GetSys(i),
00304        arr2.data_GetSys(j));
00305    data_Add(res);
00306   }
00307  }
00308 }
00309 
00310 void mcMathOrSystemHelpers::math_OrMerge(const mcMathOrSystem &arr1,
00311             const mcMathOrSystem &arr2)
00312 {
00313  mcMATHLOG(wxT("mcMathOrSystemHelpers::math_OrMerge - merging [%s] with [%s]"), 
00314     mcTXT(arr1), mcTXT(arr2));
00315  
00316  // we just have to copy arr1 and then
00317  // add to *this the mcMathAndSystems of arr2
00318  data_Clear();
00319  data_DeepCopy(arr1.chlp());
00320 
00321  for (int i=0; i < arr2.data_GetCount(); i++)
00322   data_Add(new mcMathAndSystem(arr2.data_GetSys(i)));
00323 }
00324 
00325 mcMathSystemType mcMathOrSystemHelpers::math_GetMathSystemType() const
00326 {
00327  // set us to a system containing equations which is a
00328  // "neutral type" for the math_CombineWith function 
00329  mcMathSystemType ret(mcMSTL1_EQUATIONS);
00330 
00331  if (data_GetCount() == 0)
00332   return mcMSTL1_NOT_RECOGNIZED;
00333 
00334  // combine the types of all mcMathOrSystems...
00335  for (int i=0; i<data_GetCount(); i++)
00336   ret.math_CombineWith(data_GetSys(i).math_GetMathSystemType());
00337  return ret;
00338 }
00339 
00340 


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

[ Top ]