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