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)
30 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
31 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
33 bool aReadyToDisplay = false;
35 ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
36 ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
38 // one object is a feature Line, other object is a point result. We check shape of point result
39 aReadyToDisplay = aObj1.get() && aObj2.get() &&
40 (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
41 SketcherPrs_Tools::getShape(aObj2).get() != NULL);
43 return aReadyToDisplay;
46 bool SketcherPrs_Middle::updateIfReadyToDisplay(double theStep) const
48 if (!IsReadyToDisplay(myConstraint, myPlane))
50 ObjectPtr aPointObject;
52 // find a line result to set middle symbol near it
53 AttributePtr anAttribute = SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
54 if (!anAttribute.get()) {
55 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
56 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
57 if (aShape.get() && aShape->isEdge())
60 if (!aPointObject.get()) {
61 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
62 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
63 if (aShape.get() && aShape->isEdge())
67 if (!aPointObject.get())
70 // Set points of the presentation
71 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
72 gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
73 myPntArray->SetVertice(1, aP1);
77 void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
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);
85 ObjectPtr aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
86 drawLine(thePrs, theColor, aObject);
88 aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
89 drawLine(thePrs, theColor, aObject);
92 void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
93 Quantity_Color theColor, const ObjectPtr& theObject) const
95 FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
96 if (aLineFeature.get()) {
97 std::list<ResultPtr> aResults = aLineFeature->results();
98 if (aResults.size() == 1) {
99 ResultPtr aResult = aResults.front();
100 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
101 if (aLine.get() != NULL)
102 drawShape(aLine, thePrs);
106 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
107 if (aLine.get() != NULL)
108 drawShape(aLine, thePrs);