]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Transformation.cpp
Salome HOME
Fix for selection of translation and rotation constraints
[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 <SketchPlugin_MultiRotation.h>
13 #include <SketchPlugin_MultiTranslation.h>
14 #include <ModelAPI_AttributeInteger.h>
15 #include <ModelAPI_AttributeRefList.h>
16
17 #include <Graphic3d_AspectLine3d.hxx>
18 #include <Prs3d_Root.hxx>
19
20
21
22 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
23 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
24
25 static Handle(Image_AlienPixMap) MyPixMap;
26
27 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint, 
28                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
29                                            bool isTranslation) 
30  : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
31 {
32   int aPointsNb = 0;
33   if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
34     aPointsNb = theConstraint->integer(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID())->value();
35   } else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
36     aPointsNb = theConstraint->integer(SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID())->value();
37   }
38   aPointsNb == 0 ? aPointsNb = 2 : aPointsNb++; // by default we have 2 points for symbols
39   myPntArray = new Graphic3d_ArrayOfPoints(aPointsNb);
40 }  
41
42 bool SketcherPrs_Transformation::updatePoints(double theStep) const 
43 {
44   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
45   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
46   if (anAttrB.get() == NULL)
47     return false;
48
49   int aNbB = anAttrB->size();
50   if (aNbB == 0)
51     return false;
52
53   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
54
55   int i;
56   ObjectPtr aObj;
57   gp_Pnt aP1;
58   for (i = 0; i < aNbB; i++) {
59     aObj = anAttrB->object(i);
60     if (!aObj.get()) // TODO:empty_result
61       // this check should be removed here after the result flush is corrected
62       // the problem is, that feature::execute() flushes redisplay by each result creation
63       // but it is possible(e.g. in the sketch circle, that there should be more than one result.
64       // Here, crash happens, because the second result is not created yet
65       continue;
66     aP1 = aMgr->getPosition(aObj, this, theStep);
67     myPntArray->SetVertice(i + 1, aP1);
68   }  
69
70   return true;
71 }
72
73 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
74 {
75   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
76   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
77   if (anAttrB.get() == NULL)
78     return;
79
80   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
81
82   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
83   aGroup->SetPrimitivesAspect(aLineAspect);
84
85   drawListOfShapes(anAttrB, thePrs);
86 }
87