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

mcFractionHelpers Class Reference

#include <Fraction.h>

Inheritance diagram for mcFractionHelpers:

Inheritance graph
[legend]
Collaboration diagram for mcFractionHelpers:

Collaboration graph
[legend]
List of all members.

Detailed Description

A little class containing the DATA, MATH, GUI and IO sections of this element (as instances and not pointers).

This is entirely defined & implemented through macros.

Definition at line 55 of file Fraction.h.

Public Member Functions

 mcFractionHelpers ()
virtual ~mcFractionHelpers ()
int data_GetChildrenCount () const
 Returns the number of children attached to this tree node.
const mcElementdata_GetConstChild (int n) const
 Returns the n-th tree node attached to this element.
void data_SetChild (int n, const mcElement &newchild)
 math_Replaces the idx-th child of this element with a copy of the given one.
void data_DeepCopy (const mcElementHelpers *p)
 Deep copies all the info contained in this class.
bool data_isSameAs (const mcElementHelpers *p) const
 Performs a deep comparison of the data hold by this class and the data hold by the given mcElementHelpers object.
void data_SetDen (const mcPolynomial &p)
 Copies the given polynomial, setting it as the denominator of the fraction.
void data_SetNum (const mcPolynomial &p)
 Copies the given polynomial, setting it as the numerator of the fraction.
virtual void data_AddElements (bool bNum, mcElement *p, int num, int pos=-1, bool bOverwrite=FALSE, bool bForceCopy=FALSE)
 math_Adds the given elements to the numerator/denominator.
mcPolynomialdata_GetNum ()
mcPolynomialdata_GetDen ()
const mcPolynomialdata_GetNum () const
const mcPolynomialdata_GetDen () const
void math_Flip ()
 Exchanges the numerator with the denominator.
bool io_isBeginTag (const wxXml2Node &tag) const
 Returns a positive value if the given MathML content tag marks the begin of this element; FALSE otherwise.
bool io_isBeginChar (const wxString &str) const
 Returns a positive value if the given inlined expression marks the begin of this element; FALSE otherwise.
void io_Set (const wxString &num, const wxString &den)
 Imports as inlined expressions the two given strings in the numerator and denominator.
void io_SetNum (const wxString &num)
void io_SetDen (const wxString &den)
wxXml2Node io_GetMathML (bool bGetPresentation) const
 Returns the MathML code for this element as presentation markup (http://www.w3.org/TR/MathML2/chapter3.html) or as content markup (http://www.w3.org/TR/MathML2/chapter4.html).
wxString io_GetInlinedExpr () const
 Returns the inlined expression for this element as a wxString.
bool io_CheckBracketNeed (const mcPolynomial &p, const wxString &exp) const
bool io_ImportPresentationMathML (wxXml2Node tag, wxString &pErr)
 Imports presentation MathML reading the contents of the given XML node (without modifying it).
bool io_ImportInlinedExpr (const wxString &str, int *count, wxString &pErr)
 Imports an inlined expression.
mcFraction-specific functions
Some mcFraction utility functions.

wxPoint gui_GetNumPos () const
wxPoint gui_GetDenPos () const
void gui_SetCursorOnDen (mcCursorPos cp=mcCP_END)
void gui_SetCursorOnNum (mcCursorPos cp=mcCP_END)
mcElement abstract functions
The following functions implement the abstract mcElement methods.

void gui_UpdateExpDepth ()
 A mcFraction needs to change exponent depth of numerator and denominator.
bool gui_isBeginKey (const mcKey &ev) const
 Returns a positive value if the given character marks the begin of this element; FALSE otherwise.
bool gui_isEndKey (const mcKey &ev) const
 Returns TRUE if the given character marks the end of this element; this function is always called before calling ::gui_Input function.
mcInputRes gui_Input (const mcKey &ev, mcElement *newelem)
 This function is called when the cursor is inside the element and the user presses a key (which is not the element's end tag).
mcInsertRes gui_Insert (const mcElement &, mcElement *)
 Inserts the given element at the right of the cursor position.
mcMoveCursorRes gui_MoveCursor (mcMoveCursorFlag flag, long modifiers)
 This function is called to move the cursor which is inside the element, one 'step' left, right, up or down (when flag=mcMCF_LEFT/mcMCF_RIGHT/mcMCF_UP/mcMCF_DOWN).
void gui_GetCursorPos (mcCursorPos &) const
 Returns the cursor position as Cursor Position flag.
int gui_MoveCursorUsingPoint (wxDC &dc, const wxPoint &p)
 Moves the cursor inside this element in the closest available position to the given point.
int gui_Draw (wxDC &dc, int x, int y, long flags, const wxPoint &pt) const
 element must be drawn with mcElementHelpers::sgui_m_pActivationBrush background brush; if this pointer is equal to mcDRW_NONACTIVE, the function must simply draw everything with default transparent mode; if the pointer is not one of the previous values, the function must use the pointer to find the subelement where it lies.
int gui_GetRelCursorPos (wxDC &dc, wxPoint *pt) const
 Returns the height of the cursor and the (x;y) position of the cursor (in the given pointer) relative to the top-left point of this element.
int gui_GetYAnchor () const
 Returns the y amount of this mcElement to subtract from the center line to draw this element.
void gui_SetCursorPos (const mcCursorPos &)
 Sets the cursor position inside the element using Cursor Position flags.
void gui_OnSelect (wxDC &dc, wxRect &rc)
 This function is called when the bounding box of this element intersects with the selection rectangle created by the user with the mouse cursor.
void gui_DoRecalcSize ()
 This function is called by mcElement and non-mcElement functions when the internal size variable must be updated due to a change in the structure of the element.
mcElement gui_GetSelection () const
 Returns the selected portion of this element.
void gui_DeleteSelection ()
 Deletes the selected children of this element, without breaking the integrity of this element: a data_Check() constcall after this function should throw no errors.
mcElementMath abstract functions
Implementation of abstract general math functions.

bool math_CanBeMultWith (const mcElement &p) const
 Works like #math_CanBemath_AddeWith(), just for multiplication.
bool math_CanBeAddedWith (const mcElement &p) const
 Returns TRUE if this element can be added with the given element.
bool math_CanBeDivBy (const mcElement &p) const
 Works like #math_CanBemath_AddeWith(), just for divisions.
virtual mcBasicOpRes math_Add (const mcElement &, mcElement *p, bool add)
 Sums or subtracts this element with the given e element.
virtual mcBasicOpRes math_MultiplyBy (const mcElement &, mcElement *p)
 Multiplies two mcElements of the same type and stores the result in this object.
virtual mcBasicOpRes math_DivideBy (const mcElement &, mcElement *p)
 Divides two mcElements of the same type and stores the result in this object.
mcRealValue math_GetLenght () const
 Returns the 'lenght' of this element without taking in count its children.
int math_GetOrderPos () const
 Returns the order position for this element.
mcMathType math_GetMathType () const
 A powerful recognizer function which automatically classifies the type of the math data contained in this class and returns the respective identifier.
mcBasicOpRes math_MakeReciprocal (mcElement *)
 Calculates the reciprocal of this element; tipically, this function creates a mcFraction whose numerator is 1 and the denominator contains *this.
mcExpSimRes math_Simplify (long flags, mcElement *newelem)
 Simplifies this element one "step"; that is, after one call to this function the element must be slightly changed.
mcExpSimRes math_Expand (long flags, mcElement *newelem)
 Expands this element one "step".
bool math_Compare (const mcElement &p, long flags) const
 Compares *this element with the given one and then compare the children of *this and the children of the given element, too.
mcRealValue math_Evaluate () const
 Evaluates the numeric value of this element and then returns it.
void math_SetExp (const mcPolynomial &p)
 Sets the exponent of this element to match the given polynomial.
mcBasicOpRes math_RaiseTo (const mcPolynomial &p)
 Raises *this element to the given polynomial.
mcMonomial math_GetLCM (const mcElement &) const
 Returns the LCM between *this and the given element.
mcMonomial math_GetGCD (const mcElement &) const

Static Public Attributes

static mcKeysgui_pNewFraction = NULL
 The key to use to create this element.
static int sgui_nSpaceAboveBelow = 2
 The space left above & below fraction.
static int sgui_nSpaceBetween = 1
 The space above and below fraction line.
static int sgui_nAdditionalWidth = 4
 The additional fraction line's lenght used to make it look better.
static int sgui_nAdditionalSpace = 8
 The space which is left empty on the left and on the right of the fraction line to make everything look better.

Protected Member Functions

void gui_Init ()
 Inits this section of the element.
mcExpSimRes math_SimplifyFactors (long flags, mcElement *newelem)

Protected Attributes

mcPolynomial mdata_eNum
 The numerator.
mcPolynomial mdata_eDen
 The denominator.
int mgui_nCursorPos
 The current cursor location.

Private Member Functions

 mcDEFINE_REFERENCE_DATA (mcFraction, mcET_FRACTION)


Constructor & Destructor Documentation

mcFractionHelpers::mcFractionHelpers  )  [inline]
 

Definition at line 107 of file Fraction.h.

virtual mcFractionHelpers::~mcFractionHelpers  )  [inline, virtual]
 

Definition at line 108 of file Fraction.h.


Member Function Documentation

void mcFractionHelpers::data_AddElements bool  bNum,
mcElement p,
int  num,
int  pos = -1,
bool  bOverwrite = FALSE,
bool  bForceCopy = FALSE
[virtual]
 

math_Adds the given elements to the numerator/denominator.

Definition at line 79 of file Fraction.cpp.

References mcElementArray::data_AddElements(), data_GetDen(), and data_GetNum().

void mcFractionHelpers::data_DeepCopy const mcElementHelpers p  )  [inline, virtual]
 

Deep copies all the info contained in this class.

The mcElement implementation should be enough because all the element's data should be contained inside the associated mcElementData derived class. In fact, mcElementData does not provide a standard implementation of the DeepCopy() function. mcElement-derived classes, instead, should not contain any other variable, so this function should be enough....

Reimplemented from mcElementHelpers.

Definition at line 152 of file Fraction.h.

References mcElementHelpers::data_DeepCopy(), mcElement::data_DeepCopy(), mdata_eDen, mdata_eNum, and mgui_nCursorPos.

int mcFractionHelpers::data_GetChildrenCount  )  const [inline, virtual]
 

Returns the number of children attached to this tree node.

This function can be used on *any* mcElement node because this is a virtual function which is overridden by container classes which thus return the correct number of children.

This function is used by various mcElement functions like data_Check() const data_GetElemFromID(), ... which must call some standard mcElement functions on all nodes attached to this element.

Reimplemented from mcElementHelpers.

Definition at line 128 of file Fraction.h.

References mcElementHelpers::data_GetChildrenCount().

const mcElement& mcFractionHelpers::data_GetConstChild int  n  )  const [inline, virtual]
 

Returns the n-th tree node attached to this element.

You can use this function to traverse the entire tree:

     mcElement rootnode = [...];
     MyWalkerFnc(rootnode);
    
     void MyWalkerFnc(mcElement p) {
    
         // do what you want on the "p" node...
    
         for (int i=0; i < p.data_GetChildrenCount(); i++)
             MyWalkerFnc(p.data_GetChild(i));
     }

Parameters:
n The n-th child of this object.

Reimplemented from mcElementHelpers.

Definition at line 134 of file Fraction.h.

References mcEmptyElement, and mcRETURN_ELEMENT_CHILD.

const mcPolynomial& mcFractionHelpers::data_GetDen  )  const [inline]
 

Definition at line 191 of file Fraction.h.

mcPolynomial& mcFractionHelpers::data_GetDen  )  [inline]
 

Definition at line 189 of file Fraction.h.

Referenced by data_AddElements(), gui_DeleteSelection(), gui_DoRecalcSize(), gui_Draw(), gui_GetDenPos(), gui_GetRelCursorPos(), gui_GetSelection(), gui_Input(), gui_Insert(), gui_isEndKey(), gui_MoveCursor(), gui_MoveCursorUsingPoint(), gui_OnSelect(), io_GetInlinedExpr(), io_GetMathML(), io_ImportPresentationMathML(), io_SetDen(), math_Add(), math_Compare(), math_DivideBy(), math_Evaluate(), math_Expand(), math_Flip(), math_GetGCD(), math_GetLCM(), math_GetMathType(), math_MultiplyBy(), math_RaiseTo(), math_Simplify(), and math_SimplifyFactors().

const mcPolynomial& mcFractionHelpers::data_GetNum  )  const [inline]
 

Definition at line 190 of file Fraction.h.

mcPolynomial& mcFractionHelpers::data_GetNum  )  [inline]
 

Definition at line 188 of file Fraction.h.

Referenced by data_AddElements(), gui_DeleteSelection(), gui_DoRecalcSize(), gui_Draw(), gui_GetDenPos(), gui_GetNumPos(), gui_GetRelCursorPos(), gui_GetSelection(), gui_GetYAnchor(), gui_Input(), gui_Insert(), gui_isEndKey(), gui_MoveCursor(), gui_MoveCursorUsingPoint(), gui_OnSelect(), io_GetInlinedExpr(), io_GetMathML(), io_ImportPresentationMathML(), io_SetNum(), math_Add(), math_Compare(), math_Evaluate(), math_Expand(), math_Flip(), math_GetGCD(), math_GetLCM(), math_GetMathType(), math_MultiplyBy(), math_RaiseTo(), math_Simplify(), and math_SimplifyFactors().

bool mcFractionHelpers::data_isSameAs const mcElementHelpers p  )  const [inline, virtual]
 

Performs a deep comparison of the data hold by this class and the data hold by the given mcElementHelpers object.

Reimplemented from mcElementHelpers.

Definition at line 160 of file Fraction.h.

References mdata_eDen, and mdata_eNum.

void mcFractionHelpers::data_SetChild int  n,
const mcElement newchild
[inline, virtual]
 

math_Replaces the idx-th child of this element with a copy of the given one.

Reimplemented from mcElementHelpers.

Definition at line 143 of file Fraction.h.

References mcASSERT, mcET_POLYNOMIAL, and mcSET_ELEMENT_CHILD.

void mcFractionHelpers::data_SetDen const mcPolynomial p  )  [inline]
 

Copies the given polynomial, setting it as the denominator of the fraction.

Definition at line 172 of file Fraction.h.

References mcElement::data_Check().

Referenced by math_Add().

void mcFractionHelpers::data_SetNum const mcPolynomial p  )  [inline]
 

Copies the given polynomial, setting it as the numerator of the fraction.

Definition at line 179 of file Fraction.h.

References mcElement::data_Check().

void mcFractionHelpers::gui_DeleteSelection  )  [virtual]
 

Deletes the selected children of this element, without breaking the integrity of this element: a data_Check() constcall after this function should throw no errors.

The caller should first check if the element is entirely selected; if it is, the element should be deleted (by the caller) and this function should not be called. This is a recursive function.

Reimplemented from mcElementHelpers.

Definition at line 577 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcPolynomial::gui_AddNewEmptyMonomial(), mcElementHelpers::gui_DeleteSelection(), and mcElementHelpers::gui_RecalcSize().

void mcFractionHelpers::gui_DoRecalcSize  )  [virtual]
 

This function is called by mcElement and non-mcElement functions when the internal size variable must be updated due to a change in the structure of the element.

This function should be as fast and accurate as possible and it must store the new size in the mgui_sz variable.

Note:
It's very important, to maintain the size member updated, to call, in the other mcElement functions, gui_RecalcSize() every time size could have changed (for example, in gui_Input(), mcElementData setters...).

Implements mcElementHelpers.

Definition at line 160 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElementHelpers::gui_GetHeight(), mcElementHelpers::gui_GetWidth(), mcMAX, sgui_nAdditionalSpace, sgui_nAdditionalWidth, sgui_nSpaceAboveBelow, and sgui_nSpaceBetween.

int mcFractionHelpers::gui_Draw wxDC &  dc,
int  x,
int  y,
long  flags,
const wxPoint &  pt
const [virtual]
 

element must be drawn with mcElementHelpers::sgui_m_pActivationBrush background brush; if this pointer is equal to mcDRW_NONACTIVE, the function must simply draw everything with default transparent mode; if the pointer is not one of the previous values, the function must use the pointer to find the subelement where it lies.

Then, only the subelement's gui_Draw() function must be called with the initial pointer. The subelements must be called with mcDRW_ALLACTIVE flag only for special reasons.

Returns:
The ID of the element marked as active (the element which is drawn with mcElementHelpers::sgui_m_pActivationBrush as background), or mcDRW_NOACTIVEELEM flag if this element does not contain the mouse cursor.

Implements mcElementHelpers.

Definition at line 242 of file Fraction.cpp.

References data_GetDen(), mcElementHelpers::data_GetID(), data_GetNum(), mcElement::gui_Draw(), gui_GetDenPos(), mcElement::gui_GetHeight(), gui_GetNumPos(), mcElementHelpers::gui_GetSize(), mcElementHelpers::gui_GetThickness(), mcElementHelpers::gui_GetWidth(), mcDRW_ALLOW_TOTAL_SELECTION, mcDRW_NOACTIVEELEM, mcDRW_NONACTIVE, mcDRW_USEPOINT, sgui_nAdditionalSpace, sgui_nSpaceAboveBelow, and sgui_nSpaceBetween.

void mcFractionHelpers::gui_GetCursorPos mcCursorPos  )  const [virtual]
 

Returns the cursor position as Cursor Position flag.

It must return mcCP_BEGIN if cursor is at the leftmost point of the element, mcCP_END if the cursor is at the rightmost point of the element, mcCP_INSIDE otherwise. When this function is called the cursor is always inside the element.

Implements mcElementHelpers.

Definition at line 542 of file Fraction.cpp.

References mcCursorPos::gui_Push(), mcCP_BEGIN, mcCP_END, mcFRACTION_LEFTMOST, mcFRACTION_RIGHTMOST, and mgui_nCursorPos.

wxPoint mcFractionHelpers::gui_GetDenPos  )  const
 

Definition at line 181 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElementHelpers::gui_GetHeight(), mcElementHelpers::gui_GetWidth(), sgui_nSpaceAboveBelow, and sgui_nSpaceBetween.

Referenced by gui_Draw(), gui_GetRelCursorPos(), gui_MoveCursorUsingPoint(), and gui_OnSelect().

wxPoint mcFractionHelpers::gui_GetNumPos  )  const
 

Definition at line 174 of file Fraction.cpp.

References data_GetNum(), mcElementHelpers::gui_GetWidth(), and sgui_nSpaceAboveBelow.

Referenced by gui_Draw(), gui_GetRelCursorPos(), gui_MoveCursorUsingPoint(), and gui_OnSelect().

int mcFractionHelpers::gui_GetRelCursorPos wxDC &  dc,
wxPoint *  pt
const [virtual]
 

Returns the height of the cursor and the (x;y) position of the cursor (in the given pointer) relative to the top-left point of this element.

The function must fill the wxPoint pointer using coordinates relative to the top-left point of its bounding rectangle. When this function is called, the cursor is always inside the element.

Parameters:
dc The device context where the element was drawn last time.
pt The coordinates, relative to the element (assume the element placed at 0;0), indicating the top-left point of the cursor.

Implements mcElementHelpers.

Definition at line 501 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), gui_GetDenPos(), gui_GetNumPos(), mcElement::gui_GetRelCursorPos(), mcElementHelpers::gui_GetSize(), mcFRACTION_INSIDEDEN, mcFRACTION_INSIDENUM, mcFRACTION_LEFTMOST, mcFRACTION_RIGHTMOST, and mgui_nCursorPos.

mcElement mcFractionHelpers::gui_GetSelection  )  const [virtual]
 

Returns the selected portion of this element.

If this element is entirely selected (this is the default for non-container elements), the entire element should be returned (this is what the default implementation does). Container elements should override this function returning only the selected elements (in mcMonomials, mcBrackets, mcPolynomials...) or the entire element itself if it is entirely selected. This functions returns an object and not a reference to an object (as for example does gui_GetActiveElem) because the selection cannot be modified through this function.

Reimplemented from mcElementHelpers.

Definition at line 552 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElement::gui_GetSelection(), mcElementHelpers::gui_isAllSelected(), mcElement::gui_isSelected(), and mcASSERT.

int mcFractionHelpers::gui_GetYAnchor  )  const [virtual]
 

Returns the y amount of this mcElement to subtract from the center line to draw this element.

Reimplemented from mcElementHelpers.

Definition at line 153 of file Fraction.cpp.

References data_GetNum(), mcElement::gui_GetHeight(), mcElementHelpers::gui_GetThickness(), sgui_nSpaceAboveBelow, and sgui_nSpaceBetween.

void mcFractionHelpers::gui_Init  )  [inline, protected, virtual]
 

Inits this section of the element.

Acts like a constructor (it's called by mcElementHelpers).

Reimplemented from mcElementHelpers.

Definition at line 112 of file Fraction.h.

References mcElementHelpers::gui_Init(), and mcFRACTION_INSIDENUM.

mcInputRes mcFractionHelpers::gui_Input const mcKey ev,
mcElement newelem
[virtual]
 

This function is called when the cursor is inside the element and the user presses a key (which is not the element's end tag).

The way the element should process the given character is dependent to the element type: a mcNumber will insert vk next to the cursor position if vk is a digit. If vk is not acceptable, the function should call the MathCore error-handler function, mcMathCore::Get()->SyntaxError. This function should return one of the values defined for mcInputRes: mcIR_OKAY, mcIR_DELETE_THIS, mcIR_DIRECT_DELETE, mcIR_DELETE_NEXT.

Parameters:
ev The wxWidgets key event for the keypress. It contains the untraslated code for the input key; see wxWidgets KeyCodes for more info.
newelem If the function returns mcIR_REPLACE_THIS, the caller will use this pointer as a substitute for this element (which will be deleted).

Implements mcElementHelpers.

Definition at line 329 of file Fraction.cpp.

References mcElementHelpers::data_AddProperty(), data_GetDen(), data_GetNum(), mcElementHelpers::data_hasProperty(), mcPolynomial::gui_AddNewEmptyMonomial(), mcElement::gui_Input(), mcElementHelpers::gui_RecalcSize(), mcASSERT, mcEP_INITIALIZED, mcFRACTION_INSIDEDEN, mcFRACTION_INSIDENUM, mcFRACTION_LEFTMOST, mcFRACTION_RIGHTMOST, mcIR_DELETE_NEXT, mcIR_DELETE_PREVIOUS, mcIR_DELETE_THIS, mcIR_OKAY, mgui_nCursorPos, and sgui_pNewFraction.

mcInsertRes mcFractionHelpers::gui_Insert const mcElement ,
mcElement
[virtual]
 

Inserts the given element at the right of the cursor position.

Implements mcElementHelpers.

Definition at line 386 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElement::gui_Insert(), mcASSERT, mcFRACTION_INSIDEDEN, mcFRACTION_INSIDENUM, mcINSR_OKAY, and mgui_nCursorPos.

bool mcFractionHelpers::gui_isBeginKey const mcKey ev  )  const [virtual]
 

Returns a positive value if the given character marks the begin of this element; FALSE otherwise.

The begin character cannot be dependent from any variable; it must be always the same. The character is given both as ASCII code and as virtual key code.

Parameters:
ev The wxWidgets key event for the keypress. It contains the untraslated code for the input key; see wxWidgets KeyCodes for more info.
Returns:
A value identifying the subclass of this element that matched the given character; if the element has no subclasses it should return a null value when the given character is the begin character of the element. See MathCore::NewElem for more info.

Implements mcElementHelpers.

Definition at line 125 of file Fraction.cpp.

References sgui_pNewFraction.

bool mcFractionHelpers::gui_isEndKey const mcKey ev  )  const [virtual]
 

Returns TRUE if the given character marks the end of this element; this function is always called before calling ::gui_Input function.

isEndChar can return values dependent from the cursor position. The character is given both as ASCII code and as virtual key code

Parameters:
ev The wxWidgets key event for the keypress. It contains the untraslated code for the input key; see wxWidgets KeyCodes for more info.

Implements mcElementHelpers.

Definition at line 132 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcMathCore::Get(), mcElement::gui_isEndKey(), mcMathCore::m_pCancelKey, mcKey::MatchKey(), mcASSERT, mcFRACTION_INSIDEDEN, mcFRACTION_INSIDENUM, mcFRACTION_LEFTMOST, mcFRACTION_RIGHTMOST, and mgui_nCursorPos.

mcMoveCursorRes mcFractionHelpers::gui_MoveCursor mcMoveCursorFlag  flag,
long  modifiers
[virtual]
 

This function is called to move the cursor which is inside the element, one 'step' left, right, up or down (when flag=mcMCF_LEFT/mcMCF_RIGHT/mcMCF_UP/mcMCF_DOWN).

Elements which cannot move the cursor in the given direction, should call mcMathCore::Get()->SyntaxError() function. If the cursor must 'exit' the element (because its at the end, for example) the function must return mcMCR_SETFOCUS_PREVIOUS or mcMCR_SETFOCUS_NEXT. This function must always return the code mcMCR_SETFOCUS_* or mcMCR_OKAY. When this function is called, cursor is always inside the element.

Parameters:
flag One of the Move Cursor flags (see MathTypes.h)

Implements mcElementHelpers.

Definition at line 404 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElement::gui_MoveCursor(), mcElement::gui_SetCursorPos(), mcCP_BEGIN, mcFRACTION_INSIDEDEN, mcFRACTION_INSIDENUM, mcFRACTION_LEFTMOST, mcFRACTION_RIGHTMOST, mcMCF_DOWN, mcMCF_LEFT, mcMCF_RIGHT, mcMCF_UP, mcMCR_OKAY, mcMCR_SETFOCUS_ABOVE, mcMCR_SETFOCUS_BELOW, mcMCR_SETFOCUS_NEXT, mcMCR_SETFOCUS_PREVIOUS, and mgui_nCursorPos.

int mcFractionHelpers::gui_MoveCursorUsingPoint wxDC &  dc,
const wxPoint &  p
[virtual]
 

Moves the cursor inside this element in the closest available position to the given point.

The function must use the given point to set its internal cursor-position variables (when this function is called, the given point is always inside the bounding rectangle of the element, but maybe the cursor is not).

Parameters:
dc The device context where the element was drawn last time
p a valid pointer to a wxPoint (containing coord. relative to the top-left point of the element) which must be used to find the selected subelement; otherwise this is a NULL value

Implements mcElementHelpers.

Definition at line 483 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), gui_GetDenPos(), gui_GetNumPos(), mcElementHelpers::gui_GetSize(), mcElement::gui_MoveCursorUsingPoint(), mcFRACTION_INSIDEDEN, mcFRACTION_INSIDENUM, mcMCR_OKAY, and mgui_nCursorPos.

void mcFractionHelpers::gui_OnSelect wxDC &  dc,
wxRect &  rc
[virtual]
 

This function is called when the bounding box of this element intersects with the selection rectangle created by the user with the mouse cursor.

The standard implementation just selects this element. If you are implementing a container element, you must override this function and check contained elements' bounding boxes and then call the gui_OnSelect() function of the contained elements whose bounding boxes intersect the given selection rectangle.

Reimplemented from mcElementHelpers.

Definition at line 190 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElementHelpers::gui_DeSelect(), gui_GetDenPos(), gui_GetNumPos(), mcElementHelpers::gui_GetSize(), mcElementHelpers::gui_isSelected(), mcElement::gui_OnSelect(), mcElementHelpers::gui_Select(), and mcElementHelpers::gui_SelectAll().

void mcFractionHelpers::gui_SetCursorOnDen mcCursorPos  cp = mcCP_END  )  [inline]
 

Definition at line 214 of file Fraction.h.

References mcElement::gui_SetCursorPos(), and mcFRACTION_INSIDEDEN.

void mcFractionHelpers::gui_SetCursorOnNum mcCursorPos  cp = mcCP_END  )  [inline]
 

Definition at line 219 of file Fraction.h.

References mcElement::gui_SetCursorPos(), and mcFRACTION_INSIDENUM.

void mcFractionHelpers::gui_SetCursorPos const mcCursorPos  )  [virtual]
 

Sets the cursor position inside the element using Cursor Position flags.

When it's called to set the cursor at the end of the base, code==mcCP_END and data_hasProperty(mcEP_HASEXPONENT) == FALSE, when it's called to set the cursor at the beginning of the base, code==mcCP_BEGIN. The function doesnt need to care for the third Cursor Position flag: mcCP_INSIDE, actually this function will never be called with this code.

Implements mcElementHelpers.

Definition at line 532 of file Fraction.cpp.

References mcASSERT, mcFRACTION_LEFTMOST, mcFRACTION_RIGHTMOST, and mgui_nCursorPos.

void mcFractionHelpers::gui_UpdateExpDepth  )  [inline, virtual]
 

A mcFraction needs to change exponent depth of numerator and denominator.

Reimplemented from mcElementHelpers.

Definition at line 234 of file Fraction.h.

References mcElement::gui_SetAtSameLevelOf(), and mcElementHelpers::gui_UpdateExpDepth().

bool mcFractionHelpers::io_CheckBracketNeed const mcPolynomial p,
const wxString &  exp
const
 

Definition at line 624 of file Fraction.cpp.

References mcElementArray::data_Get(), mcElementArray::data_GetCount(), mcElement::data_GetType(), mcEmptyElement, mcET_BRACKET, and mcET_MONOMIAL.

Referenced by io_GetInlinedExpr().

wxString mcFractionHelpers::io_GetInlinedExpr  )  const [virtual]
 

Returns the inlined expression for this element as a wxString.

"Inlined expression" means a math representation of the data in a single line: to allow such a restriction (everything must be on one text line), some standard conventions (and many brackets !!!) are used:

  • "^" introduces an exponent
  • "_" introduces a subscript Some examples of inlined expressions are: "4x^2+5a*sin(x/4)", "cos^2(PI/2)+ (123ax+b)/c >= 0", ....

Implements mcElementHelpers.

Definition at line 644 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), io_CheckBracketNeed(), and mcElement::io_GetInlinedExpr().

wxXml2Node mcFractionHelpers::io_GetMathML bool  bGetPresentation  )  const [virtual]
 

Returns the MathML code for this element as presentation markup (http://www.w3.org/TR/MathML2/chapter3.html) or as content markup (http://www.w3.org/TR/MathML2/chapter4.html).

Parameters:
bGetPresentation TRUE if you want to get the presentation markup, FALSE if you want the content MathML.
Returns:
The XML tree containing the MathML code for this element.

Implements mcElementHelpers.

Definition at line 600 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), and mcElement::io_GetMathML().

bool mcFractionHelpers::io_ImportInlinedExpr const wxString &  str,
int *  count,
wxString &  pErr
[virtual]
 

Imports an inlined expression.

"Inlined expression" means a string containing an encoded representation of math data: 234^2*ax+6y/2=0 is an inlined expression. This is the form which is used to input and output math data by a lot of math programs. Compability with these programs is crucial. However, because of the nature of this representation, the algorithm which recognizes (through io_isBeginChar functions) the elements to create, needs to know the lenght of the token which encodes this element; this is accomplished with the count parameter which must *absolutely* be set by this function.

Parameters:
str The string containing the inlined expression to import.
count A pointer where is stored the number of characters of str imported by this function.
pErr The string where the error description is placed, if the function returns FALSE.
Returns:
TRUE on success: the first (and eventually the following) characters of the given string represent an encoded inline expression of this element and they were successfully recognized and imported.

Implements mcElementHelpers.

Definition at line 693 of file Fraction.cpp.

References mcASSERT, and mcUNUSED.

bool mcFractionHelpers::io_ImportPresentationMathML wxXml2Node  tag,
wxString &  pErr
[virtual]
 

Imports presentation MathML reading the contents of the given XML node (without modifying it).

This function is called only if io_isBeginTag function returns a positive value for the name of parent tag of pTag.

Parameters:
pTag The wxXML_***_NODE class to parse.
pErr The string where the error description is placed, if the function returns FALSE.
Returns:
TRUE on success (no mismatched or invalid tags).

Implements mcElementHelpers.

Definition at line 660 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), and mcASSERT.

bool mcFractionHelpers::io_isBeginChar const wxString &  str  )  const [inline, virtual]
 

Returns a positive value if the given inlined expression marks the begin of this element; FALSE otherwise.

The begin tag cannot be dependent from any variable; it must be always the same.

Implements mcElementHelpers.

Definition at line 329 of file Fraction.h.

bool mcFractionHelpers::io_isBeginTag const wxXml2Node &  tag  )  const [inline, virtual]
 

Returns a positive value if the given MathML content tag marks the begin of this element; FALSE otherwise.

The begin tag cannot be dependent from any variable; it must be always the same.

Parameters:
tag The string containing the TAG to test.
Returns:
A value identifying the subclass of this element that matched the given character; if the element has no subclasses it should return a null value when the given character is the begin character of the element. See MathCore::NewElem for more info

Implements mcElementHelpers.

Definition at line 323 of file Fraction.h.

void mcFractionHelpers::io_Set const wxString &  num,
const wxString &  den
[inline]
 

Imports as inlined expressions the two given strings in the numerator and denominator.

Definition at line 336 of file Fraction.h.

void mcFractionHelpers::io_SetDen const wxString &  den  ) 
 

Definition at line 715 of file Fraction.cpp.

References data_GetDen(), and mcElement::io_ImportInlinedExpr().

void mcFractionHelpers::io_SetNum const wxString &  num  ) 
 

Definition at line 706 of file Fraction.cpp.

References data_GetNum(), and mcElement::io_ImportInlinedExpr().

mcBasicOpRes mcFractionHelpers::math_Add const mcElement ,
mcElement p,
bool  add
[virtual]
 

Sums or subtracts this element with the given e element.

A unique function for add/subtract operations is used because the algorithms used to handle this two operations are usually almost identic and thus this avoids a lot of repetitions.

If the two elements cannot be summed, then an ASSERT should fail since before using this function, the caller should always use the math_CanBeAddedWith() function.

The function returns one of mcBasicOpRes values, eventually using the pp pointer to store the replacement element which will be used by the caller in case this function returns mcBOR_REPLACE_OPERAND or mcBOR_REPLACE_BOTH.

Implements mcElementHelpers.

Definition at line 812 of file Fraction.cpp.

References mcPolynomial::data_AddNewMonomial(), mcElementArray::data_DeleteAll(), mcFraction::data_GetDen(), data_GetDen(), mcFraction::data_GetNum(), data_GetNum(), data_SetDen(), math_GetLCM(), mcElement::math_SimpleAdd(), mcElement::math_SimpleDivideBy(), mcElement::math_SimpleMultiplyBy(), mcElement::math_SimpleSubtract(), mcASSERT, mcBOR_REMOVE_OPERAND, mcET_BRACKET, mcET_FRACTION, mcET_FUNCTION, mcET_MONOMIAL, mcET_NUMBER, mcET_POLYNOMIAL, mcET_RADICAL, and mcET_SYMBOL.

bool mcFractionHelpers::math_CanBeAddedWith const mcElement p  )  const [virtual]
 

Returns TRUE if this element can be added with the given element.

If the function returns TRUE, then the math_Add() function should return one of mcBOR_REMOVE_OPERAND, mcBOR_REPLACE_BOTH or mcBOR_REPLACE_OPERAND.

Implements mcElementHelpers.

Definition at line 804 of file Fraction.cpp.

bool mcFractionHelpers::math_CanBeDivBy const mcElement p  )  const [virtual]
 

Works like #math_CanBemath_AddeWith(), just for divisions.

Implements mcElementHelpers.

Definition at line 807 of file Fraction.cpp.

bool mcFractionHelpers::math_CanBeMultWith const mcElement p  )  const [virtual]
 

Works like #math_CanBemath_AddeWith(), just for multiplication.

Implements mcElementHelpers.

Definition at line 801 of file Fraction.cpp.

bool mcFractionHelpers::math_Compare const mcElement p,
long  flags
const [virtual]
 

Compares *this element with the given one and then compare the children of *this and the children of the given element, too.

If they are the same, then the function returns TRUE; FALSE otherwise. This function is different from #math_hasSameContentOf() because it doesn't work on MaxSimply()ed copies. This function tipically uses the math_CompareThisOnly() function.

Implements mcElementHelpers.

Definition at line 744 of file Fraction.cpp.

References mcFraction::data_GetDen(), data_GetDen(), mcFraction::data_GetNum(), data_GetNum(), mcElement::math_Compare(), and mcET_FRACTION.

mcBasicOpRes mcFractionHelpers::math_DivideBy const mcElement ,
mcElement p
[virtual]
 

Divides two mcElements of the same type and stores the result in this object.

Parameters:
p A pointer to a mcElement of the same type of this mcElement, which will be used to divide this mcElement.

Implements mcElementHelpers.

Definition at line 907 of file Fraction.cpp.

References mcElement::data_Check(), data_GetDen(), mcFraction::math_Flip(), mcElement::math_SimpleMultiplyBy(), mcASSERT, mcBOR_REMOVE_OPERAND, mcBOR_REPLACE_OPERAND_AND_SET_MULTOP, and mcET_FRACTION.

mcRealValue mcFractionHelpers::math_Evaluate  )  const [virtual]
 

Evaluates the numeric value of this element and then returns it.

The evaluation can proceed *only* if this element does _not_ contain any parameter or unknown; in case it contains one of these, then the returned value is *mcRealValue::pNAN.

Implements mcElementHelpers.

Definition at line 771 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcValue::isValid(), and mcElement::math_Evaluate().

mcExpSimRes mcFractionHelpers::math_Expand long  flags,
mcElement newelem
[virtual]
 

Expands this element one "step".

expanding means that the aim of this function is exactly the opposite of math_Simplify: instead making the function body shorter, it tries to make it as long as possible:

(x - 2)^3 . first call to math_Expand x^3 - 6x^2 + 12x -8

Implements mcElementHelpers.

Definition at line 1080 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElementArray::math_Expand(), mcESR_DONE, and mcESR_NOTFINISHED.

void mcFractionHelpers::math_Flip  ) 
 

Exchanges the numerator with the denominator.

Definition at line 785 of file Fraction.cpp.

References data_GetDen(), and data_GetNum().

mcMonomial mcFractionHelpers::math_GetGCD const mcElement  )  const [virtual]
 

Implements mcElementHelpers.

Definition at line 1112 of file Fraction.cpp.

References mcFraction::data_GetDen(), data_GetDen(), mcFraction::data_GetNum(), data_GetNum(), mcFraction::data_SetDen(), mcFraction::data_SetNum(), and mcElement::math_GetGCD().

mcMonomial mcFractionHelpers::math_GetLCM const mcElement  )  const [virtual]
 

Returns the LCM between *this and the given element.

Implements mcElementHelpers.

Definition at line 1099 of file Fraction.cpp.

References mcFraction::data_GetDen(), data_GetDen(), mcFraction::data_GetNum(), data_GetNum(), mcFraction::data_SetDen(), mcFraction::data_SetNum(), and mcElement::math_GetLCM().

Referenced by math_Add().

mcRealValue mcFractionHelpers::math_GetLenght  )  const [inline, virtual]
 

Returns the 'lenght' of this element without taking in count its children.

The wxT('lenght') of this element is the 'complexity' represented by the data placed in the mcElementData of this element. This is a key function for the simplify and expand routines of MathCore because through the use of this value, the system is able to decide if an operation determines a simplification or a complication. The simple example below shows how this can be done:

          mcPolynomial mypol(NULL);
          mypol.Init("2^16");
          mcRealValue n1 = mypol.math_GetTotalLenght(); */

(The math_GetTotalLenght() function works using this function !) The default implementation returns zero. This is a valid behaviour only for container elements, that is, for those elements where only the children carry information. For simple elements and for those containers which stand for an operation (like mcFraction which implies a division), the default implementation must be overridden.

A lenght/complexity of 1 means that this element would require only a single byte of memory if stored in an ASCII string. An element long 2 units (like mcBracket) would require 2 bytes (one for the left parenthesis and one for the right one)...

Implements mcElementHelpers.

Definition at line 293 of file Fraction.h.

mcMathType mcFractionHelpers::math_GetMathType  )  const [virtual]
 

A powerful recognizer function which automatically classifies the type of the math data contained in this class and returns the respective identifier.

Implements mcElementHelpers.

Definition at line 755 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcMathType::m_tMath1, mcElementHelpers::math_ContainsUnknowns(), mcElement::math_GetMathType(), mcMathType::math_MultiplyBy(), and mcMTL1_RATIONAL.

int mcFractionHelpers::math_GetOrderPos  )  const [inline, virtual]
 

Returns the order position for this element.

Implements mcElementHelpers.

Definition at line 294 of file Fraction.h.

mcBasicOpRes mcFractionHelpers::math_MakeReciprocal mcElement  )  [inline, virtual]
 

Calculates the reciprocal of this element; tipically, this function creates a mcFraction whose numerator is 1 and the denominator contains *this.

This should be the default behaviour. A simple multiplication of the current exponent by -1 should be avoided when possible.

Note:
The math_RaiseTo function could be used instead of this one but this function should be preferred over math_RaiseTo(mcPolynomial(-1)); because this function ?????????? FIXME

Reimplemented from mcElementHelpers.

Definition at line 297 of file Fraction.h.

References mcBOR_REMOVE_OPERAND.

mcBasicOpRes mcFractionHelpers::math_MultiplyBy const mcElement ,
mcElement p
[virtual]
 

Multiplies two mcElements of the same type and stores the result in this object.

Parameters:
p A pointer to a mcElement of the same type of this mcElement, which will be multiplied with this mcElement.

Implements mcElementHelpers.

Definition at line 876 of file Fraction.cpp.

References mcFraction::data_GetDen(), data_GetDen(), mcFraction::data_GetNum(), data_GetNum(), mcElement::math_SimpleMultiplyBy(), mcASSERT, mcBOR_REMOVE_OPERAND, and mcET_FRACTION.

mcBasicOpRes mcFractionHelpers::math_RaiseTo const mcPolynomial p  )  [virtual]
 

Raises *this element to the given polynomial.

Returns mcBOR_INVALID if the operation could not be performed (this is typically because the base is negative), or mcBOR_REMOVE_OPERAND if the operation was okay.

Note:
All MathCore elements must implement this function, not only mcExpElement-derived classes because this operation *must* be feasible on every element: those elements which do not hold an exponent, must raise their children directly. mcFraction, for example, must implement this operation directly raising the numerator & denominator.

Implements mcElementHelpers.

Definition at line 1125 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcElement::math_SimpleRaiseTo(), and mcBOR_REMOVE_OPERAND.

void mcFractionHelpers::math_SetExp const mcPolynomial p  )  [virtual]
 

Sets the exponent of this element to match the given polynomial.

As for math_RaiseTo, for elements which do not have an exponent by their own, this function should just call the children's math_SetExp functions.

Reimplemented from mcElementHelpers.

Definition at line 731 of file Fraction.cpp.

References mcASSERT.

mcExpSimRes mcFractionHelpers::math_Simplify long  flags,
mcElement newelem
[virtual]
 

Simplifies this element one "step"; that is, after one call to this function the element must be slightly changed.

For example, this monomial requires three calls to math_Simplify to be completely reduced in a basic form:

12ax*3 + 4a/(x^-1) . first call to math_Simplify 36ax + 4a/(1/x) . second call 36ax + 4ax . third call 40ax

Returns:
Returns TRUE if the element is completely simplied and thus, the following calls to math_Simplify won't have effect.

Implements mcElementHelpers.

Definition at line 948 of file Fraction.cpp.

References data_GetDen(), data_GetNum(), mcExpContainer::data_SetContent(), mcPolynomial::math_ChangeAllSigns(), mcElement::math_Evaluate(), mcPolynomial::math_isFactorized(), mcPolynomial::math_isFirstMonomialNegative(), mcElementArray::math_Simplify(), math_SimplifyFactors(), mcESR_CHANGE_SIGN, mcESR_DONE, mcESR_NOTFINISHED, and mcESR_REPLACE_THIS.

mcExpSimRes mcFractionHelpers::math_SimplifyFactors long  flags,
mcElement newelem
[protected]
 

Definition at line 1015 of file Fraction.cpp.

References mcElementArray::data_AddElements(), mcElement::data_Check(), data_GetDen(), data_GetNum(), mcElement::math_CanBeDivBy(), mcElement::math_DivideBy(), mcElementArray::math_Get(), mcPolynomial::math_Get(), mcElementArray::math_GetCount(), mcElementArray::math_MathToDataIdx(), mcElementArray::math_Remove(), mcASSERT, mcBOR_INVALID, mcBOR_REMOVE_OPERAND, mcBOR_REPLACE_OPERAND, mcESR_DONE, mcESR_NOTFINISHED, mcMATHLOG, mcTXT, and mcUNUSED.

Referenced by math_Simplify().

mcFractionHelpers::mcDEFINE_REFERENCE_DATA mcFraction  ,
mcET_FRACTION 
[private]
 


Member Data Documentation

mcPolynomial mcFractionHelpers::mdata_eDen [protected]
 

The denominator.

Definition at line 66 of file Fraction.h.

Referenced by data_DeepCopy(), and data_isSameAs().

mcPolynomial mcFractionHelpers::mdata_eNum [protected]
 

The numerator.

Definition at line 63 of file Fraction.h.

Referenced by data_DeepCopy(), and data_isSameAs().

int mcFractionHelpers::mgui_nCursorPos [protected]
 

The current cursor location.

Definition at line 76 of file Fraction.h.

Referenced by data_DeepCopy(), gui_GetCursorPos(), gui_GetRelCursorPos(), gui_Input(), gui_Insert(), gui_isEndKey(), gui_MoveCursor(), gui_MoveCursorUsingPoint(), and gui_SetCursorPos().

int mcFractionHelpers::sgui_nAdditionalSpace = 8 [static]
 

The space which is left empty on the left and on the right of the fraction line to make everything look better.

Definition at line 63 of file Fraction.cpp.

Referenced by gui_DoRecalcSize(), and gui_Draw().

int mcFractionHelpers::sgui_nAdditionalWidth = 4 [static]
 

The additional fraction line's lenght used to make it look better.

Definition at line 62 of file Fraction.cpp.

Referenced by gui_DoRecalcSize().

int mcFractionHelpers::sgui_nSpaceAboveBelow = 2 [static]
 

The space left above & below fraction.

Definition at line 60 of file Fraction.cpp.

Referenced by gui_DoRecalcSize(), gui_Draw(), gui_GetDenPos(), gui_GetNumPos(), and gui_GetYAnchor().

int mcFractionHelpers::sgui_nSpaceBetween = 1 [static]
 

The space above and below fraction line.

Definition at line 61 of file Fraction.cpp.

Referenced by gui_DoRecalcSize(), gui_Draw(), gui_GetDenPos(), and gui_GetYAnchor().

mcKey * mcFractionHelpers::sgui_pNewFraction = NULL [static]
 

The key to use to create this element.

Definition at line 69 of file Fraction.cpp.

Referenced by gui_Input(), and gui_isBeginKey().


The documentation for this class was generated from the following files:

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

[ Top ]