Salome HOME
Prepare version 1.2.1: quick fix for iteration 2 release
[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
16
17
18 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
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
30 bool SketcherPrs_Mirror::updatePoints(double theStep) const
31 {
32   ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
33   if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
34     return false;
35
36   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
37   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
38   if (anAttrB.get() == NULL)
39     return false;
40   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
41   if (anAttrC.get() == NULL)
42     return false;
43
44   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
45   int aNb = anAttrB->size();
46   if (aNb != anAttrC->size())
47     return false;
48
49   myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
50   int i;
51   ObjectPtr aObj;
52   gp_Pnt aP1;
53   for (i = 0; i < aNb; i++) {
54     aObj = anAttrB->object(i);
55     if (!aObj.get()) // TODO:empty_result
56       // this check should be removed here after the result flush is corrected
57       // the problem is, that feature::execute() flushes redisplay by each result creation
58       // but it is possible(e.g. in the sketch circle, that there should be more than one result.
59       // Here, crash happens, because the second result is not created yet
60       continue;
61     aP1 = aMgr->getPosition(aObj, this, theStep);
62     myPntArray->SetVertice(i + 1, aP1);
63   }  
64   for (i = 0; i < aNb; i++) {
65     aObj = anAttrC->object(i);
66     if (!aObj.get()) // TODO:empty_result
67       // this check should be removed here after the result flush is corrected
68       // the problem is, that feature::execute() flushes redisplay by each result creation
69       // but it is possible(e.g. in the sketch circle, that there should be more than one result.
70       // Here, crash happens, because the second result is not created yet
71       continue;
72     aP1 = aMgr->getPosition(aObj, this, theStep);
73     myPntArray->SetVertice(aNb + i + 1, aP1);
74   }  
75   return true;
76 }
77
78
79 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
80 {
81   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
82   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
83   if (anAttrB.get() == NULL)
84     return;
85   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
86   if (anAttrC.get() == NULL)
87     return;
88
89   int aNb = anAttrB->size();
90   if (aNb != anAttrC->size())
91     return;
92
93   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
94
95   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
96   aGroup->SetPrimitivesAspect(aLineAspect);
97
98   // Draw axis line
99   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
100
101   // Draw source objects
102   drawListOfShapes(anAttrB, thePrs);
103
104   // draw mirrored objects
105   drawListOfShapes(anAttrC, thePrs);
106 }
107