Salome HOME
Temporary fix, which will be corrected by MPV. Crash fix: Create circle, translation...
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Transformation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Transformation.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Transformation.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <SketchPlugin_Constraint.h>
12 #include <ModelAPI_AttributeRefList.h>
13
14 #include <Graphic3d_AspectLine3d.hxx>
15 #include <Prs3d_Root.hxx>
16
17
18
19 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
20 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
21
22 static Handle(Image_AlienPixMap) MyPixMap;
23
24 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint, 
25                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
26                                            bool isTranslation) 
27  : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
28 {
29 }  
30
31 bool SketcherPrs_Transformation::updatePoints(double theStep) const 
32 {
33   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
34   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
35   if (anAttrB.get() == NULL)
36     return false;
37
38   int aNbB = anAttrB->size();
39   if (aNbB == 0)
40     return false;
41
42   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
43   myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
44
45   int i;
46   ObjectPtr aObj;
47   gp_Pnt aP1;
48   for (i = 0; i < aNbB; i++) {
49     aObj = anAttrB->object(i);
50     if (!aObj.get()) // TODO:empty_result
51       // this check should be removed here after the result flush is corrected
52       // the problem is, that feature::execute() flushes redisplay by each result creation
53       // but it is possible(e.g. in the sketch circle, that there should be more than one result.
54       // Here, crash happens, because the second result is not created yet
55       continue;
56     aP1 = aMgr->getPosition(aObj, this, theStep);
57     myPntArray->SetVertice(i + 1, aP1);
58   }  
59
60   return true;
61 }
62
63 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
64 {
65   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
66   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
67   if (anAttrB.get() == NULL)
68     return;
69
70   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
71
72   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
73   aGroup->SetPrimitivesAspect(aLineAspect);
74
75   drawListOfShapes(anAttrB, thePrs);
76 }
77