Salome HOME
43a57aa9f0636b7d630d248a805a96e9a4443d7b
[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_MultiTranslation.h>
13 #include <SketchPlugin_MultiRotation.h>
14 #include <ModelAPI_AttributeRefList.h>
15 #include <GeomDataAPI_Point2D.h>
16
17 #include <Graphic3d_AspectLine3d.hxx>
18 #include <Prs3d_Root.hxx>
19 #include <Geom_CartesianPoint.hxx>
20 #include <gp_Pnt.hxx>
21 #include <StdPrs_Point.hxx>
22
23
24
25 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
26 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
27
28 static Handle(Image_AlienPixMap) MyPixMap;
29
30 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint, 
31                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
32                                            bool isTranslation) 
33  : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
34 {
35 }  
36
37 bool SketcherPrs_Transformation::updatePoints(double theStep) const 
38 {
39   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
40   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
41   if (anAttrB.get() == NULL)
42     return false;
43
44   int aNbB = anAttrB->size();
45   if (aNbB == 0)
46   {
47 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
48   //if (!myPntArray.IsNull())
49     //  mySPoints.Clear();
50 #endif
51     return false;
52   }
53
54   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
55   myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
56
57   int i;
58   ObjectPtr aObj;
59   gp_Pnt aP1;
60   for (i = 0; i < aNbB; i++) {
61     aObj = anAttrB->object(i);
62     aP1 = aMgr->getPosition(aObj, this, theStep);
63     myPntArray->SetVertice(i + 1, aP1);
64   }  
65
66   return true;
67 }
68
69 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
70 {
71   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
72   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
73   if (anAttrB.get() == NULL)
74     return;
75
76   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
77
78   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
79   aGroup->SetPrimitivesAspect(aLineAspect);
80
81   drawListOfShapes(anAttrB, thePrs);
82   if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
83     std::shared_ptr<GeomDataAPI_Point2D> aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
84         aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID()));
85     std::shared_ptr<GeomDataAPI_Point2D> aEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
86         aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID()));
87   
88     if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
89       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aStart->x(), aStart->y());
90       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
91       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
92
93       aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
94       aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
95       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
96     }
97   } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
98     std::shared_ptr<GeomDataAPI_Point2D> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
99         aData->attribute(SketchPlugin_MultiRotation::CENTER_ID()));
100     if (aCenter.get() && aCenter->isInitialized()) {
101       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
102       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
103       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
104     }
105   }
106 }
107