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 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName);
74 if (aLine.get() == NULL)
76 std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
78 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
79 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
81 Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1);
82 aLines->AddVertex(aPnt1->impl<gp_Pnt>());
83 aLines->AddVertex(aPnt2->impl<gp_Pnt>());
84 theGroup->AddPrimitiveArray(aLines);
87 void SketcherPrs_SymbolPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
88 const SelectMgr_SequenceOfOwner& theOwners)
91 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
92 aSelectionPrs->Clear();
93 drawLines(aSelectionPrs, Quantity_NOC_WHITE);
95 aSelectionPrs->SetDisplayPriority(9);
96 aSelectionPrs->Display();
97 thePM->Highlight(this);
100 void SketcherPrs_SymbolPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
101 const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
103 thePM->Color(this, theColor);
105 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
106 aHilightPrs->Clear();
107 drawLines(aHilightPrs, theColor);
109 if (thePM->IsImmediateModeOn())
110 thePM->AddToImmediateList(aHilightPrs);
115 void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
116 const Standard_Integer aMode)
120 if (!myPntArray.IsNull()) {
121 Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
122 for (int i = 1; i <= myPntArray->VertexNumber(); i++) {
123 Handle(Select3D_SensitivePoint) aSP = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(i));
124 aSelection->Add(aSP);