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::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
39 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
41 bool aReadyToDisplay = false;
43 std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
44 // Get transformated objects list
45 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
46 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
47 if (anAttrB.get() == NULL)
48 return aReadyToDisplay;
50 int aNbB = anAttrB->size();
51 aReadyToDisplay = aNbB > 0;
53 #ifdef DEBUG_HIDE_COPY_ATTRIBUTE
55 if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
56 // If it is translation
57 AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
58 SketchPlugin_MultiTranslation::START_POINT_ID());
59 AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
60 SketchPlugin_MultiTranslation::END_POINT_ID());
63 aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
65 else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
67 AttributePoint2DPtr aCenter =
68 GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
69 aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
72 return aReadyToDisplay;
75 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep) const
77 if (!IsReadyToDisplay(myConstraint, myPlane))
80 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
81 // Get transformated objects list
82 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
83 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
85 int aNbB = anAttrB->size();
88 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
89 //if (!myPntArray.IsNull())
94 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
95 myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
100 // Compute points of symbols
101 for (i = 0; i < aNbB; i++) {
102 aObj = anAttrB->object(i);
103 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
105 aP1 = aMgr->getPosition(aObj, this, theStep);
106 myPntArray->SetVertice(i + 1, aP1);
112 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs,
113 Quantity_Color theColor) const
115 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
116 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
117 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
118 if (anAttrB.get() == NULL)
121 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
123 // drawListOfShapes uses myDrawer for attributes definition
124 Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
125 myDrawer->SetLineAspect(aLnAspect);
127 drawListOfShapes(anAttrB, thePrs);
128 if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
129 // If it is translation
130 AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
131 SketchPlugin_MultiTranslation::START_POINT_ID());
132 AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
133 SketchPlugin_MultiTranslation::END_POINT_ID());
135 if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
137 std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aStart->x(), aStart->y());
138 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
139 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
142 aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
143 aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
144 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
146 } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
148 AttributePoint2DPtr aCenter =
149 GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
150 if (aCenter.get() && aCenter->isInitialized()) {
151 // Show center of rotation
152 std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
153 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
154 StdPrs_Point::Add(thePrs, aPoint, myDrawer);