Salome HOME
d544bbc0248587bbd9b5e27e76deaaa6c1a62421
[modules/shaper.git] / src / PartSet / PartSet_CenterPrs.cpp
1 // Copyright (C) 2017-2023  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 <Graphic3d_ArrayOfPoints.hxx>
31 #include <AIS_InteractiveContext.hxx>
32
33
34 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
35
36
37 PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject,
38                                      const GeomEdgePtr& theEdge,
39                                      const gp_Pnt& theCenter,
40                                      ModelAPI_AttributeSelection::CenterType theType)
41   : AIS_Point(new Geom_CartesianPoint(theCenter)),
42   myObject(theObject),
43   myEdge(theEdge),
44   myCenterType(theType)
45 {
46   SetAutoHilight(Standard_False);
47 }
48
49 void PartSet_CenterPrs::drawPoint(const Handle(Prs3d_Presentation)& thePrs,
50                                   Quantity_Color theColor)
51 {
52   Handle(Prs3d_Drawer) aDrawer = HilightAttributes();
53
54   Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
55
56   Handle(Graphic3d_AspectMarker3d) PtA = aPntAspect->Aspect();
57   PtA->SetType(Aspect_TOM_RING1);
58   PtA->SetColor(theColor);
59
60   Handle(Geom_Point) aPnt = Component();
61   Handle(Graphic3d_Group) TheGroup = thePrs->CurrentGroup();
62   TheGroup->SetPrimitivesAspect(PtA);
63
64   Handle(Graphic3d_ArrayOfPoints) aPoint = new Graphic3d_ArrayOfPoints (1);
65   aPoint->AddVertex(aPnt->X(),aPnt->Y(),aPnt->Z());
66   TheGroup->AddPrimitiveArray(aPoint);
67
68   PtA = new Graphic3d_AspectMarker3d();
69   PtA->SetType(Aspect_TOM_POINT);
70   PtA->SetScale(5.);
71   PtA->SetColor(theColor);
72   TheGroup->SetPrimitivesAspect(PtA);
73   TheGroup->AddPrimitiveArray (aPoint);
74 }
75
76 void PartSet_CenterPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& PM,
77                                         const SelectMgr_SequenceOfOwner& /*Seq*/)
78 {
79   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( PM );
80   aSelectionPrs->Clear();
81
82   drawPoint(aSelectionPrs, GetContext()->SelectionStyle()->Color());
83
84   aSelectionPrs->SetDisplayPriority(9);
85   aSelectionPrs->Display();
86   PM->Color(this, GetContext()->SelectionStyle());
87 }
88
89 void PartSet_CenterPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
90                                               const Handle(Prs3d_Drawer)& theStyle,
91                                               const Handle(SelectMgr_EntityOwner)& /*theOwner*/)
92 {
93   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
94   aHilightPrs->Clear();
95
96   thePM->Color(this, theStyle);
97   drawPoint(aHilightPrs, theStyle->Color());
98
99   aHilightPrs->SetZLayer(Graphic3d_ZLayerId_Topmost);
100
101   if (thePM->IsImmediateModeOn())
102     thePM->AddToImmediateList(aHilightPrs);
103 }