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 <Graphic3d_AspectLine3d.hxx>
14 #include <Prs3d_Root.hxx>
17 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
18 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
20 static Handle(Image_AlienPixMap) MyPixMap;
22 SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint,
23 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
24 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
28 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
29 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
31 bool aReadyToDisplay = false;
33 ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
34 ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
36 // one object is a feature Line, other object is a point result. We check shape of point result
37 aReadyToDisplay = aObj1.get() && aObj2.get() &&
38 (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
39 SketcherPrs_Tools::getShape(aObj2).get() != NULL);
41 return aReadyToDisplay;
44 bool SketcherPrs_Middle::updateIfReadyToDisplay(double theStep) const
46 if (!IsReadyToDisplay(myConstraint, myPlane))
48 ObjectPtr aPointObject;
50 // find a line result to set middle symbol near it
51 AttributePtr anAttribute = SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
52 if (!anAttribute.get()) {
53 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
54 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
55 if (aShape.get() && aShape->isEdge())
58 if (!aPointObject.get()) {
59 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
60 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
61 if (aShape.get() && aShape->isEdge())
65 if (!aPointObject.get())
68 // Set points of the presentation
69 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
70 gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
71 myPntArray->SetVertice(1, aP1);
75 void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
77 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
79 Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
80 aGroup->SetPrimitivesAspect(aLineAspect);
83 ObjectPtr aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
84 drawLine(thePrs, theColor, aObject);
86 aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
87 drawLine(thePrs, theColor, aObject);
90 void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
91 Quantity_Color theColor, const ObjectPtr& theObject) const
93 FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
94 if (aLineFeature.get()) {
95 std::list<ResultPtr> aResults = aLineFeature->results();
96 if (aResults.size() == 1) {
97 ResultPtr aResult = aResults.front();
98 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
99 if (aLine.get() != NULL)
100 drawShape(aLine, thePrs);
104 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
105 if (aLine.get() != NULL)
106 drawShape(aLine, thePrs);