Salome HOME
Merge branch 'CPPHighAPI'
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Mirror.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Mirror.cpp
4 // Created:     6 April 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Mirror.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <SketchPlugin_Constraint.h>
12
13 #include <Graphic3d_AspectLine3d.hxx>
14 #include <Prs3d_Root.hxx>
15 #include <Prs3d_LineAspect.hxx>
16
17
18
19 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
20 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
21
22 static Handle(Image_AlienPixMap) MyPixMap;
23
24 SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, 
25                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
26  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
27 {
28 }  
29
30 bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
31                                           const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
32 {
33   bool aReadyToDisplay = false;
34
35   // Get axis of mirror
36   ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
37   if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
38     return aReadyToDisplay;
39
40   std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
41   // Get source objects
42   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
43   if (anAttrB.get() == NULL)
44     return aReadyToDisplay;
45   // Get mirrored objects
46   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
47   if (anAttrC.get() == NULL)
48     return aReadyToDisplay;
49
50   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
51   int aNb = anAttrB->size();
52   // If size of source objects and mirrored ones is not equal then the constraint is not computed
53   if (aNb != anAttrC->size())
54     return aReadyToDisplay;
55
56   aReadyToDisplay = true;
57   return aReadyToDisplay;
58 }
59
60 bool SketcherPrs_Mirror::updateIfReadyToDisplay(double theStep) const
61 {
62   if (!IsReadyToDisplay(myConstraint, myPlane))
63     return false;
64
65   // Get axis of mirror
66   ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
67
68   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
69   // Get source objects
70   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
71   // Get mirrored objects
72   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
73
74   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
75   int aNb = anAttrB->size();
76
77   myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
78   int i;
79   ObjectPtr aObj;
80   gp_Pnt aP1;
81   // get position for each source object
82   for (i = 0; i < aNb; i++) {
83     aObj = anAttrB->object(i);
84     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
85       continue;
86     aP1 = aMgr->getPosition(aObj, this, theStep);
87     myPntArray->SetVertice(i + 1, aP1);
88   }  
89   // Get position of each mirrored object
90   for (i = 0; i < aNb; i++) {
91     aObj = anAttrC->object(i);
92     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
93       continue;
94     aP1 = aMgr->getPosition(aObj, this, theStep);
95     myPntArray->SetVertice(aNb + i + 1, aP1);
96   }  
97   return true;
98 }
99
100
101 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
102 {
103   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
104   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
105   if (anAttrB.get() == NULL)
106     return;
107   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
108   if (anAttrC.get() == NULL)
109     return;
110
111   int aNb = anAttrB->size();
112   if (aNb != anAttrC->size())
113     return;
114
115   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
116
117   // drawListOfShapes uses myDrawer for attributes definition
118   Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
119   myDrawer->SetLineAspect(aLnAspect);
120
121   // Draw axis line
122   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
123
124   // Draw source objects
125   drawListOfShapes(anAttrB, thePrs);
126
127   // draw mirrored objects
128   drawListOfShapes(anAttrC, thePrs);
129 }
130