Salome HOME
Issue #847: Use white color for symbols selection
[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
31 bool SketcherPrs_Mirror::updatePoints(double theStep) const
32 {
33   ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
34   if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
35     return false;
36
37   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
38   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
39   if (anAttrB.get() == NULL)
40     return false;
41   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
42   if (anAttrC.get() == NULL)
43     return false;
44
45   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
46   int aNb = anAttrB->size();
47   if (aNb != anAttrC->size())
48     return false;
49
50   myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
51   int i;
52   ObjectPtr aObj;
53   gp_Pnt aP1;
54   for (i = 0; i < aNb; i++) {
55     aObj = anAttrB->object(i);
56     aP1 = aMgr->getPosition(aObj, this, theStep);
57     myPntArray->SetVertice(i + 1, aP1);
58   }  
59   for (i = 0; i < aNb; i++) {
60     aObj = anAttrC->object(i);
61     aP1 = aMgr->getPosition(aObj, this, theStep);
62     myPntArray->SetVertice(aNb + i + 1, aP1);
63   }  
64   return true;
65 }
66
67
68 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
69 {
70   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
71   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
72   if (anAttrB.get() == NULL)
73     return;
74   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
75   if (anAttrC.get() == NULL)
76     return;
77
78   int aNb = anAttrB->size();
79   if (aNb != anAttrC->size())
80     return;
81
82   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
83
84   //Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
85   //aGroup->SetPrimitivesAspect(aLineAspect);
86
87   // drawListOfShapes uses myDrawer for attributes definition
88   Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
89   myDrawer->SetLineAspect(aLnAspect);
90
91   // Draw axis line
92   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
93
94   // Draw source objects
95   drawListOfShapes(anAttrB, thePrs);
96
97   // draw mirrored objects
98   drawListOfShapes(anAttrC, thePrs);
99 }
100