1 // Copyright (C) 2014-2019 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
20 #include "ModuleBase_ViewerPrs.h"
22 #include <ModuleBase_ResultPrs.h>
23 #include <StdSelect_BRepOwner.hxx>
25 ModuleBase_ViewerPrs::ModuleBase_ViewerPrs(ObjectPtr theResult,
26 const GeomShapePtr& theShape,
27 Handle(SelectMgr_EntityOwner) theOwner)
28 : myResult(theResult),
34 ModuleBase_ViewerPrs::~ModuleBase_ViewerPrs()
38 bool ModuleBase_ViewerPrs::isEqual(ModuleBase_ViewerPrs* thePrs) const
40 if (!thePrs || thePrs->isEmpty())
43 bool isEqualResult = (myResult.get() == thePrs->object().get());
44 bool isEqualShape = (!myShape.get() && !thePrs->shape().get()) ||
45 (myShape.get() && myShape->isEqual(thePrs->shape()));
46 bool isEqualIO = (myInteractive == thePrs->interactive()) == Standard_True;
48 bool isEqualOwner = myOwner.get() == thePrs->owner().get();
49 if (isEqualResult && isEqualShape && isEqualIO &&
50 !isEqualOwner) { /// owners are different
51 // as we might loading object with the same shape in different modes like
52 // "objects" and "other", it is possible that two owners are created linked
53 // to one shape. We should accept such ViewerPrs as equal to current in order
54 // to do not use the same <result, shape> twice
55 Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
56 Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
57 if (!anOwner1.IsNull() && !anOwner2.IsNull())
58 isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
59 anOwner1->Shape().IsEqual(anOwner2->Shape());
62 if (isEqualResult && isEqualShape &&
63 !isEqualIO) { /// AIS are different
64 // check that the owner is a fictive owner for compsolid object, created in the
65 // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
66 // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
67 // as they use the same shape and result(of compsolid)
68 Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
69 Handle(StdSelect_BRepOwner) aCSolidOwner2 =
70 Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
71 isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
72 if (!aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull())
73 isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
74 aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
77 return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
80 bool ModuleBase_ViewerPrs::operator==(const ModuleBase_ViewerPrs& thePrs)
85 bool isEqualResult = (myResult.get() == thePrs.object().get());
86 bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
87 (myShape.get() && myShape->isEqual(thePrs.shape()));
88 bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
90 bool isEqualOwner = myOwner.get() == thePrs.owner().get();
91 if (isEqualResult && isEqualShape && isEqualIO &&
92 !isEqualOwner) { /// owners are different
93 // as we might loading object with the same shape in different modes like
94 // "objects" and "other", it is possible that two owners are created linked
95 // to one shape. We should accept such ViewerPrs as equal to current in order
96 // to do not use the same <result, shape> twice
97 Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
98 Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
99 if (!anOwner1.IsNull() && !anOwner2.IsNull())
100 isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
101 anOwner1->Shape().IsEqual(anOwner2->Shape());
104 if (isEqualResult && isEqualShape &&
105 !isEqualIO) { /// AIS are different
106 // check that the owner is a fictive owner for compsolid object, created in the
107 // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
108 // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
109 // as they use the same shape and result(of compsolid)
110 Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
111 Handle(StdSelect_BRepOwner) aCSolidOwner2 =
112 Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
113 isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
114 if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
115 isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
116 aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
119 return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;