Salome HOME
9e051971af61cd2853c8e0ea2b05a2d2ea50719c
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SymbolPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_SymbolPrs.cpp
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_SymbolPrs.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <GeomAPI_Edge.h>
11
12 #include <Graphic3d_ArrayOfSegments.hxx>
13
14 #include <SelectMgr_Selection.hxx>
15 #include <SelectMgr_EntityOwner.hxx>
16 #include <Select3D_SensitivePoint.hxx>
17
18
19 #ifdef WIN32
20 # define FSEP "\\"
21 #else
22 # define FSEP "/"
23 #endif
24
25 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
26 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
27
28
29 std::map<const char*, Handle(Image_AlienPixMap)> SketcherPrs_SymbolPrs::myIconsMap;
30
31
32 SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, 
33                                              const std::shared_ptr<GeomAPI_Ax3>& thePlane)
34  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
35 {
36   SetAutoHilight(Standard_False);
37 }
38
39
40 Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
41 {
42   if (myIconsMap.count(iconName()) == 1) {
43     return myIconsMap[iconName()];
44   }
45   TCollection_AsciiString aFile(getenv("NewGeomResources"));
46   aFile += FSEP;
47   aFile += iconName();
48   Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap();
49   if (aPixMap->Load(aFile)) {
50     myIconsMap[iconName()] = aPixMap;
51     return aPixMap;
52   }
53   return Handle(Image_AlienPixMap)();
54 }
55
56 void SketcherPrs_SymbolPrs::ClearSelected()
57 {
58   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );  
59   if( !aSelectionPrs.IsNull() ) {
60     aSelectionPrs->Clear(); 
61   }
62 }
63
64 void SketcherPrs_SymbolPrs::prepareAspect()
65 {
66   if (myAspect.IsNull()) {
67     myAspect = new Graphic3d_AspectMarker3d(icon());
68   }
69 }
70
71 void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const
72 {
73   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, theAttrName);
74   std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getLine(aObj);
75   if (aLine.get() == NULL)
76     return;
77   std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
78
79   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
80   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
81
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);
86 }
87
88 void SketcherPrs_SymbolPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
89                                            const SelectMgr_SequenceOfOwner& theOwners)
90 {
91
92   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
93   aSelectionPrs->Clear();
94   drawLines(aSelectionPrs, Quantity_NOC_WHITE);
95
96   aSelectionPrs->SetDisplayPriority(9);
97   aSelectionPrs->Display();
98   thePM->Highlight(this);
99 }
100
101 void SketcherPrs_SymbolPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
102                                                  const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
103 {
104   thePM->Color(this, theColor);
105
106   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
107   aHilightPrs->Clear();
108   drawLines(aHilightPrs, theColor);
109
110   if (thePM->IsImmediateModeOn())
111     thePM->AddToImmediateList(aHilightPrs);
112 }
113
114
115
116 void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
117                                             const Standard_Integer aMode)
118 {
119   ClearSelected();
120
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);
126     }
127   }
128 }