1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_SymbolPrs.cpp
4 // Created: 12 March 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_SymbolPrs.h"
8 #include "SketcherPrs_Tools.h"
10 #include <GeomAPI_Edge.h>
12 #include <Graphic3d_ArrayOfSegments.hxx>
14 #include <SelectMgr_Selection.hxx>
15 #include <SelectMgr_EntityOwner.hxx>
16 #include <Select3D_SensitivePoint.hxx>
25 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
26 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
29 std::map<const char*, Handle(Image_AlienPixMap)> SketcherPrs_SymbolPrs::myIconsMap;
32 SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint,
33 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
34 : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
36 SetAutoHilight(Standard_False);
40 Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
42 if (myIconsMap.count(iconName()) == 1) {
43 return myIconsMap[iconName()];
45 TCollection_AsciiString aFile(getenv("NewGeomResources"));
48 Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap();
49 if (aPixMap->Load(aFile)) {
50 myIconsMap[iconName()] = aPixMap;
53 return Handle(Image_AlienPixMap)();
56 void SketcherPrs_SymbolPrs::ClearSelected()
58 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );
59 if( !aSelectionPrs.IsNull() ) {
60 aSelectionPrs->Clear();
64 void SketcherPrs_SymbolPrs::prepareAspect()
66 if (myAspect.IsNull()) {
67 myAspect = new Graphic3d_AspectMarker3d(icon());
71 void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const
73 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, theAttrName);
74 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
75 if (aLine.get() == NULL)
77 std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
79 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
80 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
82 Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1);
83 aLines->AddVertex(aPnt1->impl<gp_Pnt>());
84 aLines->AddVertex(aPnt2->impl<gp_Pnt>());
85 theGroup->AddPrimitiveArray(aLines);
88 void SketcherPrs_SymbolPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
89 const SelectMgr_SequenceOfOwner& theOwners)
92 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
93 aSelectionPrs->Clear();
94 drawLines(aSelectionPrs, Quantity_NOC_WHITE);
96 aSelectionPrs->SetDisplayPriority(9);
97 aSelectionPrs->Display();
98 thePM->Highlight(this);
101 void SketcherPrs_SymbolPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
102 const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
104 thePM->Color(this, theColor);
106 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
107 aHilightPrs->Clear();
108 drawLines(aHilightPrs, theColor);
110 if (thePM->IsImmediateModeOn())
111 thePM->AddToImmediateList(aHilightPrs);
116 void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
117 const Standard_Integer aMode)
121 if (!myPntArray.IsNull()) {
122 Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
123 for (int i = 1; i <= myPntArray->VertexNumber(); i++) {
124 Handle(Select3D_SensitivePoint) aSP = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(i));
125 aSelection->Add(aSP);