Ejemplo n.º 1
0
/**
 * Constructor to generate object from the corresponding SBML object.
 */
CLGroup::CLGroup(const RenderGroup& source, CCopasiContainer* pParent):
  CLGraphicalPrimitive2D(source),
  CCopasiContainer("RenderGroup", pParent),
  mFontFamily(source.getFontFamily()),
  mFontSize(source.getFontSize()),
  mStartHead(source.getStartHead()),
  mEndHead(source.getEndHead()),
  mElements("GroupElements", this),
  mKey("")
{
  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderGroup", this);

  // copy the elements
  switch (source.getFontWeight())
    {
      case Text::WEIGHT_UNSET:
        this->setFontWeight(CLText::WEIGHT_UNSET);
        break;

      case Text::WEIGHT_BOLD:
        this->setFontWeight(CLText::WEIGHT_BOLD);
        break;

      default:
        this->setFontWeight(CLText::WEIGHT_NORMAL);
        break;
    }

  switch (source.getFontStyle())
    {
      case Text::STYLE_UNSET:
        this->setFontStyle(CLText::STYLE_UNSET);
        break;

      case Text::STYLE_ITALIC:
        this->setFontStyle(CLText::STYLE_ITALIC);
        break;

      default:
        this->setFontStyle(CLText::STYLE_NORMAL);
        break;
    }

  switch (source.getTextAnchor())
    {
      case Text::ANCHOR_UNSET:
        this->setTextAnchor(CLText::ANCHOR_UNSET);
        break;

      case Text::ANCHOR_END:
        this->setTextAnchor(CLText::ANCHOR_END);
        break;

      case Text::ANCHOR_MIDDLE:
        this->setTextAnchor(CLText::ANCHOR_MIDDLE);
        break;

      default:
        this->setTextAnchor(CLText::ANCHOR_START);
        break;
    }

  switch (source.getVTextAnchor())
    {
      case Text::ANCHOR_UNSET:
        this->setVTextAnchor(CLText::ANCHOR_UNSET);
        break;

      case Text::ANCHOR_BOTTOM:
        this->setVTextAnchor(CLText::ANCHOR_BOTTOM);
        break;

      case Text::ANCHOR_MIDDLE:
        this->setVTextAnchor(CLText::ANCHOR_MIDDLE);
        break;

      default:
        this->setVTextAnchor(CLText::ANCHOR_TOP);
        break;
    }

  size_t i, iMax = source.getNumElements();
  const Transformation2D* pChild = NULL;

  for (i = 0; i < iMax; ++i)
    {
      pChild = dynamic_cast<const Transformation2D*>(source.getElement((unsigned int) i));

      if (dynamic_cast<const Rectangle*>(pChild))
        {
          this->mElements.add(new CLRectangle(*static_cast<const Rectangle*>(pChild), this), true);
        }
      else if (dynamic_cast<const Ellipse*>(pChild))
        {
          this->mElements.add(new CLEllipse(*static_cast<const Ellipse*>(pChild), this), true);
        }
      else if (dynamic_cast<const RenderCurve*>(pChild))
        {
          this->mElements.add(new CLRenderCurve(*static_cast<const RenderCurve*>(pChild), this), true);
        }
      else if (dynamic_cast<const Polygon*>(pChild))
        {
          this->mElements.add(new CLPolygon(*static_cast<const Polygon*>(pChild), this), true);
        }
      else if (dynamic_cast<const Text*>(pChild))
        {
          this->mElements.add(new CLText(*static_cast<const Text*>(pChild), this), true);
        }
      else if (dynamic_cast<const Image*>(pChild))
        {
          this->mElements.add(new CLImage(*static_cast<const Image*>(pChild), this), true);
        }
      else if (dynamic_cast<const RenderGroup*>(pChild))
        {
          this->mElements.add(new CLGroup(*static_cast<const RenderGroup*>(pChild), this), true);
        }
    }
}
Ejemplo n.º 2
0
END_TEST

START_TEST ( test_RenderCurve_read_old_style )
{
  // we need to pack the curve in a group because the code to read "old style"
  // curves is in the Group class.
  std::string s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                  "<g xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
                  "  <curve>\n"
                  "    <listOfCurveSegments>\n"
                  "      <curveSegment xsi:type=\"LineSegment\">\n"
                  "        <start x=\"0\" y=\"0\" />\n"
                  "        <end x=\"10\" y=\"3\" />\n"
                  "      </curveSegment>\n"
                  "      <curveSegment xsi:type=\"LineSegment\">\n"
                  "        <start x=\"10\" y=\"3\" />\n"
                  "        <end x=\"0\" y=\"6\" />\n"
                  "      </curveSegment>\n"
                  "    </listOfCurveSegments>\n"
                  "  </curve>\n"
                  "</g>\n"
                ;
      
  XMLInputStream* pStream= new XMLInputStream(s.c_str(),false);
  XMLNode* pNode = new XMLNode(*pStream);

  RenderGroup g = RenderGroup(*pNode);
  fail_unless(g.getNumElements() == 1);
  const Transformation2D* pElement=g.getElement(0);
  fail_unless(pElement != NULL);
  if (pElement == NULL) return;
  fail_unless(pElement->getTypeCode() == SBML_RENDER_CURVE);
  const RenderCurve* pC=dynamic_cast<const RenderCurve*>(pElement);
  fail_unless(!pC->isSetMatrix());
  fail_unless(!pC->isSetStroke());
  fail_unless(!pC->isSetStrokeWidth());
  fail_unless(!pC->isSetDashArray());
  fail_unless(pC->getNumElements() == 3);
  const RenderPoint* pP=pC->getElement(0);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( pP->x().getAbsoluteValue() < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( pP->y().getAbsoluteValue() < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(1);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 10.0 ) / 10.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 3.0) / 3.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(2);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( pP->x().getAbsoluteValue() < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 6.0) / 6.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  delete pNode;
  delete pStream;
      
      
  s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<g xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
      " <curve xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
      "    <listOfCurveSegments>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"2.0\" y=\"7.71428\"/>\n"
      "        <basePoint1 x=\"10.21428\" y=\"12.0\"/>\n"
      "        <basePoint2 x=\"15.21428\" y=\"17.04464\"/>\n"
      "        <end x=\"24.05357\" y=\"15.83928\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"24.05357\" y=\"15.83928\"/>\n"
      "        <basePoint1 x=\"32.89285\" y=\"14.63392\"/>\n"
      "        <basePoint2 x=\"45.57142\" y=\"7.17856\"/>\n"
      "        <end x=\"45.57142\" y=\"7.17856\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"LineSegment\">\n"
      "        <start x=\"45.57142\" y=\"7.17856\"/>\n"
      "        <end x=\"41.46427\" y=\"2.0\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"41.46427\" y=\"2.0\"/>\n"
      "        <basePoint1 x=\"41.46427\" y=\"2.0\"/>\n"
      "        <basePoint2 x=\"31.9107\" y=\"9.14285\"/>\n"
      "        <end x=\"23.42856\" y=\"9.32142\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"23.42856\" y=\"9.32142\"/>\n"
      "        <basePoint1 x=\"14.94642\" y=\"9.49999\"/>\n"
      "        <basePoint2 x=\"7.5357\" y=\"2.71428\"/>\n"
      "        <end x=\"7.5357\" y=\"2.71428\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"LineSegment\">\n"
      "        <start x=\"7.5357\" y=\"2.71428\"/>\n"
      "        <end x=\"2.0\" y=\"7.71428\"/>\n"
      "      </curveSegment>\n"
      "    </listOfCurveSegments>\n"
      "  </curve>\n"
      "</g>\n"
    ;

  pStream= new XMLInputStream(s.c_str(),false);
  pNode = new XMLNode(*pStream);
  
  g = RenderGroup(*pNode);
  fail_unless(g.getNumElements() == 1);
  pElement=g.getElement(0);
  fail_unless(pElement != NULL);
  fail_unless(pElement->getTypeCode() == SBML_RENDER_CURVE);
  pC=dynamic_cast<const RenderCurve*>(pElement);
  fail_unless(!pC->isSetMatrix());
  fail_unless(!pC->isSetStroke());
  fail_unless(!pC->isSetStrokeWidth());
  fail_unless(!pC->isSetDashArray());
  fail_unless(pC->getNumElements() == 7);
  pP=pC->getElement(0);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.71428) / 7.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(1);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  const RenderCubicBezier* pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 10.21428) / 10.21428) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 12.0) / 12.0) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 15.21428) / 15.21428) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 17.04464) / 17.04464) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 24.05357) / 24.05357) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 15.83928) / 15.83928) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(2);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 32.89285) / 32.89285) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 14.63392) / 14.63392) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 45.57142) / 45.57142) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 7.17856) / 7.17856) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 45.57142) / 45.57142) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 7.17856) / 7.17856) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(3);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 41.46427) / 41.46427) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(4);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 41.46427) / 41.46427) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 31.9107) / 31.9107) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 9.14285) / 9.14285) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 23.42856) / 23.42856) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 9.32142) / 9.32142) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(5);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 14.94642) / 14.94642) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 9.49999) / 9.49999) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 7.5357) / 7.5357) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 2.71428) / 2.71428) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 7.5357) / 7.5357) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 2.71428) / 2.71428) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(6);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.71428) / 7.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  delete pNode;
  delete pStream;
}