Salome HOME
Copyright update 2020
[modules/shaper.git] / src / PartSet / PartSet_CenterPrs.cpp
1 // Copyright (C) 2017-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        PartSet_CenterPrs.cpp
21 // Created:     25 April 2017
22 // Author:      Vitaly SMETANNIKOV
23
24 #include "PartSet_CenterPrs.h"
25
26 #include <ModuleBase_Tools.h>
27 #include <Geom_CartesianPoint.hxx>
28 #include <Prs3d_PointAspect.hxx>
29 #include <Graphic3d_AspectMarker3d.hxx>
30 #include <Prs3d_Root.hxx>
31 #include <Graphic3d_ArrayOfPoints.hxx>
32 #include <AIS_InteractiveContext.hxx>
33
34
35 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
36
37
38 PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject,
39                                      const GeomEdgePtr& theEdge,
40                                      const gp_Pnt& theCenter,
41                                      ModelAPI_AttributeSelection::CenterType theType)
42   : AIS_Point(new Geom_CartesianPoint(theCenter)),
43   myObject(theObject),
44   myEdge(theEdge),
45   myCenterType(theType)
46 {
47   SetAutoHilight(Standard_False);
48 }
49
50 void PartSet_CenterPrs::drawPoint(const Handle(Prs3d_Presentation)& thePrs,
51                                   Quantity_Color theColor)
52 {
53   Handle(Prs3d_Drawer) aDrawer = HilightAttributes();
54
55   Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
56
57   Handle(Graphic3d_AspectMarker3d) PtA = aPntAspect->Aspect();
58   PtA->SetType(Aspect_TOM_RING1);
59   PtA->SetColor(theColor);
60
61   Handle(Geom_Point) aPnt = Component();
62   Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(thePrs);
63   TheGroup->SetPrimitivesAspect(PtA);
64
65   Handle(Graphic3d_ArrayOfPoints) aPoint = new Graphic3d_ArrayOfPoints (1);
66   aPoint->AddVertex(aPnt->X(),aPnt->Y(),aPnt->Z());
67   TheGroup->AddPrimitiveArray(aPoint);
68
69   PtA = new Graphic3d_AspectMarker3d();
70   PtA->SetType(Aspect_TOM_POINT);
71   PtA->SetScale(5.);
72   PtA->SetColor(theColor);
73   TheGroup->SetPrimitivesAspect(PtA);
74   TheGroup->AddPrimitiveArray (aPoint);
75 }
76
77 void PartSet_CenterPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& PM,
78                                         const SelectMgr_SequenceOfOwner& Seq)
79 {
80   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( PM );
81   aSelectionPrs->Clear();
82
83   drawPoint(aSelectionPrs, GetContext()->SelectionStyle()->Color());
84
85   aSelectionPrs->SetDisplayPriority(9);
86   aSelectionPrs->Display();
87   PM->Color(this, GetContext()->SelectionStyle());
88 }
89
90 void PartSet_CenterPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
91                                               const Handle(Prs3d_Drawer)& theStyle,
92                                               const Handle(SelectMgr_EntityOwner)& theOwner)
93 {
94   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
95   aHilightPrs->Clear();
96
97   thePM->Color(this, theStyle);
98   drawPoint(aHilightPrs, theStyle->Color());
99
100   aHilightPrs->SetZLayer(Graphic3d_ZLayerId_Topmost);
101
102   if (thePM->IsImmediateModeOn())
103     thePM->AddToImmediateList(aHilightPrs);
104 }