1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Transformation.cpp
4 // Created: 16 February 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Transformation.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
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>
17 #include <Graphic3d_AspectLine3d.hxx>
18 #include <Prs3d_Root.hxx>
19 #include <Prs3d_LineAspect.hxx>
20 #include <Geom_CartesianPoint.hxx>
22 #include <StdPrs_Point.hxx>
26 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
27 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
29 static Handle(Image_AlienPixMap) MyPixMap;
31 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint,
32 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
34 : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
38 bool SketcherPrs_Transformation::updatePoints(double theStep) const
40 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
41 // Get transformated objects list
42 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
43 if (anAttrB.get() == NULL)
46 int aNbB = anAttrB->size();
49 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
50 //if (!myPntArray.IsNull())
56 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
57 myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
62 // Compute points of symbols
63 for (i = 0; i < aNbB; i++) {
64 aObj = anAttrB->object(i);
65 aP1 = aMgr->getPosition(aObj, this, theStep);
66 myPntArray->SetVertice(i + 1, aP1);
72 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
74 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
75 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
76 if (anAttrB.get() == NULL)
79 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
81 //Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
82 //aGroup->SetPrimitivesAspect(aLineAspect);
84 // drawListOfShapes uses myDrawer for attributes definition
85 Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
86 myDrawer->SetLineAspect(aLnAspect);
88 drawListOfShapes(anAttrB, thePrs);
89 if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
90 // If it is translation
91 std::shared_ptr<GeomDataAPI_Point2D> aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
92 aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID()));
93 std::shared_ptr<GeomDataAPI_Point2D> aEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
94 aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID()));
96 if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
98 std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aStart->x(), aStart->y());
99 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
100 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
103 aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
104 aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
105 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
107 } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
109 std::shared_ptr<GeomDataAPI_Point2D> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
110 aData->attribute(SketchPlugin_MultiRotation::CENTER_ID()));
111 if (aCenter.get() && aCenter->isInitialized()) {
112 // Show center of rotation
113 std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
114 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
115 StdPrs_Point::Add(thePrs, aPoint, myDrawer);