COPASI API  4.16.103
Public Member Functions | Private Types | List of all members
CCopasiXMLParser::GroupElement Class Reference
Inheritance diagram for CCopasiXMLParser::GroupElement:
Inheritance graph
[legend]
Collaboration diagram for CCopasiXMLParser::GroupElement:
Collaboration graph
[legend]

Public Member Functions

virtual void end (const XML_Char *pszName)
 
 GroupElement (CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
 
virtual void start (const XML_Char *pszName, const XML_Char **papszAttrs)
 
virtual ~GroupElement ()
 
- Public Member Functions inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
 CXMLElementHandler (CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
 
virtual void end (const XML_Char *C_UNUSED(pszName))
 
virtual void reset ()
 
virtual void start (const XML_Char *C_UNUSED(pszName), const XML_Char **C_UNUSED(papszAttrs))
 
virtual ~CXMLElementHandler ()
 

Private Types

enum  Element { Group = 0, GroupChild }
 

Additional Inherited Members

- Protected Member Functions inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
void addFix (const std::string &key, CCopasiObject *pObject)
 
void deleteCurrentHandler ()
 
- Protected Attributes inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
SCopasiXMLParserCommonmCommon
 
C_INT32 mCurrentElement
 
C_INT32 mLastKnownElement
 
CCopasiXMLParsermParser
 
CXMLElementHandlermpCurrentHandler
 

Detailed Description

Definition at line 4733 of file CCopasiXMLParser.h.

Member Enumeration Documentation

Enumerator
Group 
GroupChild 

Definition at line 4740 of file CCopasiXMLParser.h.

Constructor & Destructor Documentation

CCopasiXMLParser::GroupElement::GroupElement ( CCopasiXMLParser parser,
SCopasiXMLParserCommon common 
)
CCopasiXMLParser::GroupElement::~GroupElement ( )
virtual

Destructor

Definition at line 12602 of file CCopasiXMLParser.cpp.

References pdelete.

12603 {
12605 }
#define pdelete(p)
Definition: copasi.h:215

Member Function Documentation

void CCopasiXMLParser::GroupElement::end ( const XML_Char *  pszName)
virtual

End element handler

Parameters
constXML_Char *pszName

Definition at line 12862 of file CCopasiXMLParser.cpp.

References CLText::ANCHOR_START, CLText::ANCHOR_TOP, CCopasiMessage::EXCEPTION, CCopasiObject::getObjectParent(), CLGroup::isSetEndHead(), CLGraphicalPrimitive2D::isSetFill(), CLGraphicalPrimitive2D::isSetFillRule(), CLGroup::isSetFontFamily(), CLGroup::isSetFontStyle(), CLGroup::isSetFontWeight(), CLGroup::isSetStartHead(), CLGraphicalPrimitive1D::isSetStroke(), CLGraphicalPrimitive1D::isSetStrokeWidth(), CLGroup::isSetTextAnchor(), CLGroup::isSetVTextAnchor(), CCopasiXMLParser::mCommon, MCXML, CExpatTemplate< CExpat >::mParser, CLGraphicalPrimitive2D::NONZERO, SCopasiXMLParserCommon::pGroup, CLGroup::setEndHead(), CLGraphicalPrimitive2D::setFillColor(), CLGraphicalPrimitive2D::setFillRule(), CLGroup::setFontFamily(), CLGroup::setFontStyle(), CLGroup::setFontWeight(), CLGroup::setStartHead(), CLGraphicalPrimitive1D::setStroke(), CLGraphicalPrimitive1D::setStrokeWidth(), CLGroup::setTextAnchor(), CLGroup::setVTextAnchor(), START_ELEMENT, CLText::STYLE_NORMAL, UNKNOWN_ELEMENT, and CLText::WEIGHT_NORMAL.

12863 {
12864  switch (mCurrentElement)
12865  {
12866  case Group:
12867  {
12868  if (strcmp(pszName, "Group"))
12870  pszName, "Group", mParser.getCurrentLineNumber());
12871 
12872  assert(mCommon.pGroup != NULL);
12873 
12874  // if the group is part of another group, we have to set mCommon.pGroup
12875  // to that group, otherwise, we have to set it to NULL
12876  // a group is part of another group, if its grandFather is a group
12877  // (as group elements are stored in a separate vector)
12879  CCopasiContainer* grandFather = (parent == NULL ? NULL : parent->getObjectParent());
12880 
12881  if (grandFather != NULL && dynamic_cast<CLGroup*>(grandFather) != NULL)
12882  {
12883  mCommon.pGroup = dynamic_cast<CLGroup*>(grandFather);
12884  //tell the handler where to continue
12885 
12887 
12888  //reset handler
12890  //call parent handler
12891  mParser.onEndElement(pszName);
12892 
12893  //no need to delete Handler (since it is the only one the destructor
12894  //will handle it)
12895  break;
12896  }
12897  else
12898  {
12899  if (dynamic_cast<CLStyle*>(parent) != NULL)
12900  {
12901  // if this group is the child of a style, we should set some default values on attributes
12902  // so that they are set explicitly
12903  if (!mCommon.pGroup->isSetStroke())
12904  {
12905  mCommon.pGroup->setStroke("none");
12906  }
12907 
12909  {
12911  }
12912 
12913  if (!mCommon.pGroup->isSetFill())
12914  {
12915  mCommon.pGroup->setFillColor("none");
12916  }
12917 
12918  if (!mCommon.pGroup->isSetFillRule())
12919  {
12921  }
12922 
12923  if (!mCommon.pGroup->isSetFontFamily())
12924  {
12925  mCommon.pGroup->setFontFamily("sans-serif");
12926  }
12927 
12928  if (!mCommon.pGroup->isSetFontWeight())
12929  {
12931  }
12932 
12933  if (!mCommon.pGroup->isSetFontStyle())
12934  {
12936  }
12937 
12938  if (!mCommon.pGroup->isSetTextAnchor())
12939  {
12941  }
12942 
12944  {
12946  }
12947 
12948  if (!mCommon.pGroup->isSetStartHead())
12949  {
12950  mCommon.pGroup->setStartHead("none");
12951  }
12952 
12953  if (!mCommon.pGroup->isSetEndHead())
12954  {
12955  mCommon.pGroup->setEndHead("none");
12956  }
12957  }
12958 
12959  mCommon.pGroup = NULL;
12960  }
12961 
12963 
12964  //reset handler
12966  //call parent handler
12967  mParser.onEndElement(pszName);
12968  break;
12969  }
12970 
12971  case GroupChild:
12972 
12973  // a group can have many different children
12974  if (strcmp(pszName, "Curve")
12975  && strcmp(pszName, "Text")
12976  && strcmp(pszName, "Rectangle")
12977  && strcmp(pszName, "Polygon")
12978  && strcmp(pszName, "Ellipse")
12979  && strcmp(pszName, "Group")
12980  && strcmp(pszName, "Image")
12981  )
12982  {
12984  pszName, "???", mParser.getCurrentLineNumber());
12985  }
12986 
12987  //tell the handler where to continue
12989 
12990  //no need to delete Handler (since it is the only one the destructor
12991  //will handle it)
12992  break;
12993 
12994  case UNKNOWN_ELEMENT:
12996  break;
12997 
12998  default:
13000  pszName, "???", mParser.getCurrentLineNumber());
13001  break;
13002  }
13003 
13004  return;
13005 }
void setTextAnchor(CLText::TEXT_ANCHOR anchor)
Definition: CLGroup.cpp:280
void setFontFamily(const std::string &family)
Definition: CLGroup.cpp:248
#define START_ELEMENT
bool isSetFontWeight() const
Definition: CLGroup.cpp:584
bool isSetEndHead() const
Definition: CLGroup.cpp:560
bool isSetFontFamily() const
Definition: CLGroup.cpp:568
bool isSetStartHead() const
Definition: CLGroup.cpp:552
#define MCXML
virtual void onEndElement(const XML_Char *pszName)
void setFontWeight(CLText::FONT_WEIGHT weight)
Definition: CLGroup.cpp:264
#define UNKNOWN_ELEMENT
void setVTextAnchor(CLText::TEXT_ANCHOR anchor)
Definition: CLGroup.cpp:288
bool isSetTextAnchor() const
Definition: CLGroup.cpp:775
void setEndHead(const std::string &key)
Definition: CLGroup.cpp:304
void setStroke(const std::string &key)
void setFillColor(const std::string &color)
bool isSetFontStyle() const
Definition: CLGroup.cpp:592
int getCurrentLineNumber() const
Definition: CExpat.h:470
void setStartHead(const std::string &key)
Definition: CLGroup.cpp:296
void setFontStyle(CLText::FONT_STYLE style)
Definition: CLGroup.cpp:272
void setStrokeWidth(double width)
bool isSetVTextAnchor() const
Definition: CLGroup.cpp:783
CCopasiContainer * getObjectParent() const
void setFillRule(FILL_RULE rule)
void CCopasiXMLParser::GroupElement::start ( const XML_Char *  pszName,
const XML_Char **  papszAttrs 
)
virtual

Start element handler

Parameters
constXML_Char *pszName
constXML_Char **papszAttrs

Definition at line 12607 of file CCopasiXMLParser.cpp.

References CLGroup::addChildElement(), CLText::ANCHOR_BOTTOM, CLText::ANCHOR_END, CLText::ANCHOR_MIDDLE, CLText::ANCHOR_START, CLText::ANCHOR_TOP, CLGraphicalPrimitive2D::EVENODD, CCopasiMessage::EXCEPTION, CLGroup::getElement(), CLStyle::getGroup(), CLLineEnding::getGroup(), CLGroup::getNumElements(), CLGraphicalPrimitive2D::INHERIT, CCopasiXMLParser::mCommon, MCXML, CExpatTemplate< CExpat >::mParser, CLGraphicalPrimitive2D::NONZERO, CLGraphicalPrimitive1D::parseDashArray(), CLTransformation2D::parseTransformation(), SCopasiXMLParserCommon::pGroup, SCopasiXMLParserCommon::pLineEnding, SCopasiXMLParserCommon::pStyle, CLGroup::setEndHead(), CLGraphicalPrimitive2D::setFillColor(), CLGraphicalPrimitive2D::setFillRule(), CLGroup::setFontFamily(), CLGroup::setFontSize(), CLGroup::setFontStyle(), CLGroup::setFontWeight(), CLStyle::setGroup(), CLLineEnding::setGroup(), CLGroup::setStartHead(), CLGraphicalPrimitive1D::setStroke(), CLGraphicalPrimitive1D::setStrokeWidth(), CLGroup::setTextAnchor(), CLGroup::setVTextAnchor(), strToDouble(), CLText::STYLE_ITALIC, CLText::STYLE_NORMAL, UNKNOWN_ELEMENT, CLText::WEIGHT_BOLD, and CLText::WEIGHT_NORMAL.

12609 {
12610 
12611  // TODO This will not work for groups, since the order of children is not fixed.
12612  mCurrentElement++; /* We should always be on the next element */
12613 
12614  const char * Transform;
12615  const char * Stroke;
12616  const char * StrokeWidth;
12617  const char * StrokeDashArray;
12618  const char * Fill;
12619  const char * FillRule;
12620  const char * FontFamily;
12621  const char * FontSize;
12622  const char * FontWeight;
12623  const char * FontStyle;
12624  const char * TextAnchor;
12625  const char * VTextAnchor;
12626  const char * StartHead;
12627  const char * EndHead;
12628  mpCurrentHandler = NULL;
12629  CLGroup* pGroup = NULL;
12630 
12631  switch (mCurrentElement)
12632  {
12633  case Group:
12634 
12635  if (strcmp(pszName, "Group"))
12637  pszName, "Group", mParser.getCurrentLineNumber());
12638 
12639  Transform = mParser.getAttributeValue("transform", papszAttrs, false);
12640  Stroke = mParser.getAttributeValue("stroke", papszAttrs, false);
12641  StrokeWidth = mParser.getAttributeValue("stroke-width", papszAttrs, false);
12642  StrokeDashArray = mParser.getAttributeValue("stroke-dasharray", papszAttrs, false);
12643  Fill = mParser.getAttributeValue("fill", papszAttrs, false);
12644  FillRule = mParser.getAttributeValue("fill-rule", papszAttrs, false);
12645  FontFamily = mParser.getAttributeValue("font-family", papszAttrs, false);
12646  FontSize = mParser.getAttributeValue("font-size", papszAttrs, false);
12647  FontWeight = mParser.getAttributeValue("font-weight", papszAttrs, false);
12648  FontStyle = mParser.getAttributeValue("font-style", papszAttrs, false);
12649  TextAnchor = mParser.getAttributeValue("text-anchor", papszAttrs, false);
12650  VTextAnchor = mParser.getAttributeValue("vtext-anchor", papszAttrs, false);
12651  StartHead = mParser.getAttributeValue("startHead", papszAttrs, false);
12652  EndHead = mParser.getAttributeValue("endHead", papszAttrs, false);
12653  pGroup = new CLGroup();
12654 
12655  if (Transform != NULL)
12656  {
12657  pGroup->parseTransformation(Transform);
12658  }
12659 
12660  if (Stroke != NULL)
12661  {
12662  pGroup->setStroke(Stroke);
12663  }
12664 
12665  if (StrokeWidth != NULL)
12666  {
12667  double width = strToDouble(StrokeWidth, NULL);
12668  pGroup->setStrokeWidth(width);
12669  }
12670 
12671  if (StrokeDashArray != NULL)
12672  {
12673  pGroup->parseDashArray(StrokeDashArray);
12674  }
12675 
12676  if (Fill != NULL)
12677  {
12678  pGroup->setFillColor(Fill);
12679  }
12680 
12681  if (FillRule != NULL)
12682  {
12683  std::string f(FillRule);
12684 
12685  if (f == "nonzero")
12686  {
12688  }
12689  else if (f == "evenodd")
12690  {
12692  }
12693  else
12694  {
12696  }
12697  }
12698 
12699  if (FontFamily != NULL)
12700  {
12701  pGroup->setFontFamily(FontFamily);
12702  }
12703 
12704  if (FontSize != NULL)
12705  {
12706  pGroup->setFontSize(CLRelAbsVector(FontSize));
12707  }
12708 
12709  if (FontStyle != NULL)
12710  {
12711  std::string s(FontStyle);
12712 
12713  if (s == "normal")
12714  {
12716  }
12717  else if (s == "italic")
12718  {
12720  }
12721  }
12722 
12723  if (FontWeight != NULL)
12724  {
12725  std::string s(FontWeight);
12726 
12727  if (s == "normal")
12728  {
12730  }
12731  else if (s == "bold")
12732  {
12734  }
12735  }
12736 
12737  if (TextAnchor != NULL)
12738  {
12739  std::string s(TextAnchor);
12740 
12741  if (s == "start")
12742  {
12744  }
12745  else if (s == "middle")
12746  {
12748  }
12749  else if (s == "end")
12750  {
12752  }
12753  }
12754 
12755  if (VTextAnchor != NULL)
12756  {
12757  std::string s(VTextAnchor);
12758 
12759  if (s == "top")
12760  {
12762  }
12763  else if (s == "middle")
12764  {
12766  }
12767  else if (s == "bottom")
12768  {
12770  }
12771  }
12772 
12773  if (StartHead != NULL)
12774  {
12775  pGroup->setStartHead(StartHead);
12776  }
12777 
12778  if (EndHead != NULL)
12779  {
12780  pGroup->setEndHead(EndHead);
12781  }
12782 
12783  // now we have to check where to add the group
12784  // it could belong to another group,
12785  // a style or a line ending
12786  if (mCommon.pGroup != NULL)
12787  {
12788  mCommon.pGroup->addChildElement(pGroup);
12790  }
12791  else if (mCommon.pStyle != NULL)
12792  {
12793  mCommon.pStyle->setGroup(pGroup);
12795  }
12796  else
12797  {
12798  assert(mCommon.pLineEnding != NULL);
12799  mCommon.pLineEnding->setGroup(pGroup);
12801  }
12802 
12803  assert(mCommon.pGroup != NULL);
12804  // delete the group element again since the add/set methods made a copy
12805  delete pGroup;
12806  return;
12807  break;
12808 
12809  // a group can have many different children
12810  case GroupChild:
12811 
12812  // handle the possible children
12813  if (!strcmp(pszName, "Curve"))
12814  {
12815  mpCurrentHandler = new RenderCurveElement(mParser, mCommon);
12816  }
12817  else if (!strcmp(pszName, "Text"))
12818  {
12819  mpCurrentHandler = new TextElement(mParser, mCommon);
12820  }
12821  else if (!strcmp(pszName, "Rectangle"))
12822  {
12823  mpCurrentHandler = new RectangleElement(mParser, mCommon);
12824  }
12825  else if (!strcmp(pszName, "Polygon"))
12826  {
12827  mpCurrentHandler = new PolygonElement(mParser, mCommon);
12828  }
12829  else if (!strcmp(pszName, "Ellipse"))
12830  {
12831  mpCurrentHandler = new EllipseElement(mParser, mCommon);
12832  }
12833  else if (!strcmp(pszName, "Group"))
12834  {
12836  }
12837  else if (!strcmp(pszName, "Image"))
12838  {
12839  mpCurrentHandler = new ImageElement(mParser, mCommon);
12840  }
12841 
12842  break;
12843 
12844  default:
12848  mParser.onStartElement(pszName, papszAttrs);
12849  break;
12850  }
12851 
12852  if (mpCurrentHandler != NULL)
12853  {
12855  }
12856 
12857  mpCurrentHandler->start(pszName, papszAttrs);
12858 
12859  return;
12860 }
CLLineEnding * pLineEnding
GroupElement(CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
void setTextAnchor(CLText::TEXT_ANCHOR anchor)
Definition: CLGroup.cpp:280
void setGroup(const CLGroup *group)
void setGroup(const CLGroup *pGroup)
Definition: CLStyle.cpp:75
void setFontFamily(const std::string &family)
Definition: CLGroup.cpp:248
UnknownElement mUnknownElement
const char * getAttributeValue(const std::string &name, const char **attributes, const bool &required=true) const
Definition: CExpat.h:685
#define MCXML
void parseDashArray(const std::string &s)
void setFontWeight(CLText::FONT_WEIGHT weight)
Definition: CLGroup.cpp:264
#define UNKNOWN_ELEMENT
virtual void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
void setVTextAnchor(CLText::TEXT_ANCHOR anchor)
Definition: CLGroup.cpp:288
void pushElementHandler(CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon > *elementHandler)
const CLGroup * getGroup() const
Definition: CLStyle.cpp:91
CCopasiObject * getElement(size_t n)
Definition: CLGroup.cpp:409
const CLGroup * getGroup() const
void setEndHead(const std::string &key)
Definition: CLGroup.cpp:304
void setFontSize(const CLRelAbsVector &size)
Definition: CLGroup.cpp:256
void setStroke(const std::string &key)
void setFillColor(const std::string &color)
virtual void start(const XML_Char *C_UNUSED(pszName), const XML_Char **C_UNUSED(papszAttrs))
Definition: CXMLHandler.h:87
double strToDouble(const char *str, char const **pTail)
Definition: utility.cpp:325
int getCurrentLineNumber() const
Definition: CExpat.h:470
void setStartHead(const std::string &key)
Definition: CLGroup.cpp:296
void setFontStyle(CLText::FONT_STYLE style)
Definition: CLGroup.cpp:272
void setStrokeWidth(double width)
size_t getNumElements() const
Definition: CLGroup.cpp:384
void addChildElement(const CLTransformation2D *pChild)
Definition: CLGroup.cpp:517
void setFillRule(FILL_RULE rule)
virtual void parseTransformation(const std::string &transformationString)

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