Salome HOME
Fix colors of highlighting of symbol constraints
[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_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
20
21 static Handle(Image_AlienPixMap) MyPixMap;
22
23 SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint,
24                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane)
25  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
26 {
27 }
28
29 bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
30                                           const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
31 {
32   bool aReadyToDisplay = false;
33
34   // Get axis of mirror
35   ObjectPtr aAxisObj =
36     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 =
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;
51
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;
57
58   aReadyToDisplay = true;
59   return aReadyToDisplay;
60 }
61
62 bool SketcherPrs_Mirror::updateIfReadyToDisplay(double theStep, bool withColor) const
63 {
64   if (!IsReadyToDisplay(myConstraint, myPlane))
65     return false;
66
67   // Get axis of mirror
68   ObjectPtr aAxisObj =
69     SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
70
71   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
72   // Get source objects
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());
78
79   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
80   int aNb = anAttrB->size();
81
82   myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb, withColor);
83   int i;
84   ObjectPtr aObj;
85   gp_Pnt aP1;
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)
90       continue;
91     aP1 = aMgr->getPosition(aObj, this, theStep);
92     myPntArray->SetVertice(i + 1, aP1);
93   }
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)
98       continue;
99     aP1 = aMgr->getPosition(aObj, this, theStep);
100     myPntArray->SetVertice(aNb + i + 1, aP1);
101   }
102   return true;
103 }
104
105
106 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs,
107   Quantity_Color theColor) const
108 {
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)
113     return;
114   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC =
115     aData->reflist(SketchPlugin_Constraint::ENTITY_C());
116   if (anAttrC.get() == NULL)
117     return;
118
119   int aNb = anAttrB->size();
120   if (aNb != anAttrC->size())
121     return;
122
123   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePrs);
124
125   // drawListOfShapes uses myDrawer for attributes definition
126   Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
127   myDrawer->SetLineAspect(aLnAspect);
128
129   // Draw axis line
130   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
131
132   // Draw source objects
133   drawListOfShapes(anAttrB, thePrs, theColor);
134
135   // draw mirrored objects
136   drawListOfShapes(anAttrC, thePrs, theColor);
137 }
138