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_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
20 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
22 static Handle(Image_AlienPixMap) MyPixMap;
24 SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint,
25 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
26 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
30 bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
31 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
33 bool aReadyToDisplay = false;
37 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
38 if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
39 return aReadyToDisplay;
41 std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
43 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
44 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
45 if (anAttrB.get() == NULL)
46 return aReadyToDisplay;
47 // Get mirrored objects
48 std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
49 aData->reflist(SketchPlugin_Constraint::ENTITY_C());
50 if (anAttrC.get() == NULL)
51 return aReadyToDisplay;
53 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
54 int aNb = anAttrB->size();
55 // If size of source objects and mirrored ones is not equal then the constraint is not computed
56 if (aNb != anAttrC->size())
57 return aReadyToDisplay;
59 aReadyToDisplay = true;
60 return aReadyToDisplay;
63 bool SketcherPrs_Mirror::updateIfReadyToDisplay(double theStep) const
65 if (!IsReadyToDisplay(myConstraint, myPlane))
70 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
72 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
74 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
75 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
76 // Get mirrored objects
77 std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
78 aData->reflist(SketchPlugin_Constraint::ENTITY_C());
80 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
81 int aNb = anAttrB->size();
83 myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
87 // get position for each source object
88 for (i = 0; i < aNb; i++) {
89 aObj = anAttrB->object(i);
90 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
92 aP1 = aMgr->getPosition(aObj, this, theStep);
93 myPntArray->SetVertice(i + 1, aP1);
95 // Get position of each mirrored object
96 for (i = 0; i < aNb; i++) {
97 aObj = anAttrC->object(i);
98 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
100 aP1 = aMgr->getPosition(aObj, this, theStep);
101 myPntArray->SetVertice(aNb + i + 1, aP1);
107 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs,
108 Quantity_Color theColor) const
110 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
111 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
112 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
113 if (anAttrB.get() == NULL)
115 std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
116 aData->reflist(SketchPlugin_Constraint::ENTITY_C());
117 if (anAttrC.get() == NULL)
120 int aNb = anAttrB->size();
121 if (aNb != anAttrC->size())
124 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
126 // drawListOfShapes uses myDrawer for attributes definition
127 Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
128 myDrawer->SetLineAspect(aLnAspect);
131 addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
133 // Draw source objects
134 drawListOfShapes(anAttrB, thePrs);
136 // draw mirrored objects
137 drawListOfShapes(anAttrC, thePrs);