1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "ModuleBase_ViewerPrs.h"
22 #include <ModuleBase_ResultPrs.h>
24 ModuleBase_ViewerPrs::ModuleBase_ViewerPrs(ObjectPtr theResult,
25 const GeomShapePtr& theShape,
26 Handle_SelectMgr_EntityOwner theOwner)
27 : myResult(theResult),
33 ModuleBase_ViewerPrs::~ModuleBase_ViewerPrs()
37 bool ModuleBase_ViewerPrs::isEqual(ModuleBase_ViewerPrs* thePrs) const
39 if (!thePrs || thePrs->isEmpty())
42 bool isEqualResult = (myResult.get() == thePrs->object().get());
43 bool isEqualShape = (!myShape.get() && !thePrs->shape().get()) ||
44 (myShape.get() && myShape->isEqual(thePrs->shape()));
45 bool isEqualIO = (myInteractive == thePrs->interactive()) == Standard_True;
47 bool isEqualOwner = myOwner.get() == thePrs->owner().get();
48 if (isEqualResult && isEqualShape && isEqualIO &&
49 !isEqualOwner) { /// owners are different
50 // as we might loading object with the same shape in different modes like
51 // "objects" and "other", it is possible that two owners are created linked
52 // to one shape. We should accept such ViewerPrs as equal to current in order
53 // to do not use the same <result, shape> twice
54 Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
55 Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
56 if (!anOwner1.IsNull() && !anOwner2.IsNull())
57 isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
58 anOwner1->Shape().IsEqual(anOwner2->Shape());
61 if (isEqualResult && isEqualShape &&
62 !isEqualIO) { /// AIS are different
63 // check that the owner is a fictive owner for compsolid object, created in the
64 // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
65 // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
66 // as they use the same shape and result(of compsolid)
67 Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
68 Handle(StdSelect_BRepOwner) aCSolidOwner2 =
69 Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
70 isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
71 if (!aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull())
72 isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
73 aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
76 return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
79 bool ModuleBase_ViewerPrs::operator==(const ModuleBase_ViewerPrs& thePrs)
84 bool isEqualResult = (myResult.get() == thePrs.object().get());
85 bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
86 (myShape.get() && myShape->isEqual(thePrs.shape()));
87 bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
89 bool isEqualOwner = myOwner.get() == thePrs.owner().get();
90 if (isEqualResult && isEqualShape && isEqualIO &&
91 !isEqualOwner) { /// owners are different
92 // as we might loading object with the same shape in different modes like
93 // "objects" and "other", it is possible that two owners are created linked
94 // to one shape. We should accept such ViewerPrs as equal to current in order
95 // to do not use the same <result, shape> twice
96 Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
97 Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
98 if (!anOwner1.IsNull() && !anOwner2.IsNull())
99 isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
100 anOwner1->Shape().IsEqual(anOwner2->Shape());
103 if (isEqualResult && isEqualShape &&
104 !isEqualIO) { /// AIS are different
105 // check that the owner is a fictive owner for compsolid object, created in the
106 // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
107 // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
108 // as they use the same shape and result(of compsolid)
109 Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
110 Handle(StdSelect_BRepOwner) aCSolidOwner2 =
111 Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
112 isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
113 if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
114 isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
115 aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
118 return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;