1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Middle.cpp
4 // Created: 29 February 2016
5 // Author: Natalia ERMOLAEVA
7 #include "SketcherPrs_Middle.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
11 #include <SketchPlugin_Constraint.h>
13 #include "Events_Error.h"
15 #include <Graphic3d_AspectLine3d.hxx>
16 #include <Prs3d_Root.hxx>
19 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
20 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
22 static Handle(Image_AlienPixMap) MyPixMap;
24 SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint,
25 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
26 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
28 myPntArray = new Graphic3d_ArrayOfPoints(2);
29 myPntArray->AddVertex(0., 0., 0.);
32 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
33 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
35 bool aReadyToDisplay = false;
37 ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
38 ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
40 // one object is a feature Line, other object is a point result. We check shape of point result
41 aReadyToDisplay = aObj1.get() && aObj2.get() &&
42 (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
43 SketcherPrs_Tools::getShape(aObj2).get() != NULL);
45 return aReadyToDisplay;
48 bool SketcherPrs_Middle::updatePoints(double theStep) const
50 if (!IsReadyToDisplay(myConstraint, myPlane))
52 ObjectPtr aPointObject;
54 // find a line result to set middle symbol near it
55 AttributePtr anAttribute = SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
56 if (!anAttribute.get()) {
57 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
58 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
59 if (aShape.get() && aShape->isEdge())
62 if (!aPointObject.get()) {
63 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
64 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
65 if (aShape.get() && aShape->isEdge())
69 if (!aPointObject.get())
72 // Set points of the presentation
73 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
74 gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
75 myPntArray->SetVertice(1, aP1);
79 void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
81 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
83 Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
84 aGroup->SetPrimitivesAspect(aLineAspect);
87 ObjectPtr aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
88 drawLine(thePrs, theColor, aObject);
90 aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
91 drawLine(thePrs, theColor, aObject);
94 void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
95 Quantity_Color theColor, const ObjectPtr& theObject) const
97 FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
98 if (aLineFeature.get()) {
99 std::list<ResultPtr> aResults = aLineFeature->results();
100 if (aResults.size() == 1) {
101 ResultPtr aResult = aResults.front();
102 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
103 if (aLine.get() != NULL)
104 drawShape(aLine, thePrs);
108 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
109 if (aLine.get() != NULL)
110 drawShape(aLine, thePrs);