1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Mirror.cpp
4 // Created: 6 April 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Mirror.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
11 #include <SketchPlugin_Constraint.h>
13 #include <Graphic3d_AspectLine3d.hxx>
14 #include <Prs3d_Root.hxx>
15 #include <Prs3d_LineAspect.hxx>
19 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
21 static Handle(Image_AlienPixMap) MyPixMap;
23 SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint,
24 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
25 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
29 bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
30 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
32 bool aReadyToDisplay = false;
36 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
37 if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
38 return aReadyToDisplay;
40 std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
42 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
43 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
44 if (anAttrB.get() == NULL)
45 return aReadyToDisplay;
46 // Get mirrored objects
47 std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
48 aData->reflist(SketchPlugin_Constraint::ENTITY_C());
49 if (anAttrC.get() == NULL)
50 return aReadyToDisplay;
52 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
53 int aNb = anAttrB->size();
54 // If size of source objects and mirrored ones is not equal then the constraint is not computed
55 if (aNb != anAttrC->size())
56 return aReadyToDisplay;
58 aReadyToDisplay = true;
59 return aReadyToDisplay;
62 bool SketcherPrs_Mirror::updateIfReadyToDisplay(double theStep) const
64 if (!IsReadyToDisplay(myConstraint, myPlane))
69 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
71 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
73 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
74 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
75 // Get mirrored objects
76 std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
77 aData->reflist(SketchPlugin_Constraint::ENTITY_C());
79 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
80 int aNb = anAttrB->size();
82 myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
86 // get position for each source object
87 for (i = 0; i < aNb; i++) {
88 aObj = anAttrB->object(i);
89 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
91 aP1 = aMgr->getPosition(aObj, this, theStep);
92 myPntArray->SetVertice(i + 1, aP1);
94 // Get position of each mirrored object
95 for (i = 0; i < aNb; i++) {
96 aObj = anAttrC->object(i);
97 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
99 aP1 = aMgr->getPosition(aObj, this, theStep);
100 myPntArray->SetVertice(aNb + i + 1, aP1);
106 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs,
107 Quantity_Color theColor) const
109 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
110 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
111 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
112 if (anAttrB.get() == NULL)
114 std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
115 aData->reflist(SketchPlugin_Constraint::ENTITY_C());
116 if (anAttrC.get() == NULL)
119 int aNb = anAttrB->size();
120 if (aNb != anAttrC->size())
123 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
125 // drawListOfShapes uses myDrawer for attributes definition
126 Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
127 myDrawer->SetLineAspect(aLnAspect);
130 addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
132 // Draw source objects
133 drawListOfShapes(anAttrB, thePrs);
135 // draw mirrored objects
136 drawListOfShapes(anAttrC, thePrs);