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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ModuleBase_ViewerPrs.h"
23 #include <ModuleBase_ResultPrs.h>
24 #include <StdSelect_BRepOwner.hxx>
26 ModuleBase_ViewerPrs::ModuleBase_ViewerPrs(ObjectPtr theResult,
27 const GeomShapePtr& theShape,
28 Handle_SelectMgr_EntityOwner theOwner)
29 : myResult(theResult),
35 ModuleBase_ViewerPrs::~ModuleBase_ViewerPrs()
39 bool ModuleBase_ViewerPrs::isEqual(ModuleBase_ViewerPrs* thePrs) const
41 if (!thePrs || thePrs->isEmpty())
44 bool isEqualResult = (myResult.get() == thePrs->object().get());
45 bool isEqualShape = (!myShape.get() && !thePrs->shape().get()) ||
46 (myShape.get() && myShape->isEqual(thePrs->shape()));
47 bool isEqualIO = (myInteractive == thePrs->interactive()) == Standard_True;
49 bool isEqualOwner = myOwner.get() == thePrs->owner().get();
50 if (isEqualResult && isEqualShape && isEqualIO &&
51 !isEqualOwner) { /// owners are different
52 // as we might loading object with the same shape in different modes like
53 // "objects" and "other", it is possible that two owners are created linked
54 // to one shape. We should accept such ViewerPrs as equal to current in order
55 // to do not use the same <result, shape> twice
56 Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
57 Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
58 if (!anOwner1.IsNull() && !anOwner2.IsNull())
59 isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
60 anOwner1->Shape().IsEqual(anOwner2->Shape());
63 if (isEqualResult && isEqualShape &&
64 !isEqualIO) { /// AIS are different
65 // check that the owner is a fictive owner for compsolid object, created in the
66 // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
67 // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
68 // as they use the same shape and result(of compsolid)
69 Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
70 Handle(StdSelect_BRepOwner) aCSolidOwner2 =
71 Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
72 isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
73 if (!aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull())
74 isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
75 aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
78 return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
81 bool ModuleBase_ViewerPrs::operator==(const ModuleBase_ViewerPrs& thePrs)
86 bool isEqualResult = (myResult.get() == thePrs.object().get());
87 bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
88 (myShape.get() && myShape->isEqual(thePrs.shape()));
89 bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
91 bool isEqualOwner = myOwner.get() == thePrs.owner().get();
92 if (isEqualResult && isEqualShape && isEqualIO &&
93 !isEqualOwner) { /// owners are different
94 // as we might loading object with the same shape in different modes like
95 // "objects" and "other", it is possible that two owners are created linked
96 // to one shape. We should accept such ViewerPrs as equal to current in order
97 // to do not use the same <result, shape> twice
98 Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
99 Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
100 if (!anOwner1.IsNull() && !anOwner2.IsNull())
101 isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
102 anOwner1->Shape().IsEqual(anOwner2->Shape());
105 if (isEqualResult && isEqualShape &&
106 !isEqualIO) { /// AIS are different
107 // check that the owner is a fictive owner for compsolid object, created in the
108 // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
109 // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
110 // as they use the same shape and result(of compsolid)
111 Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
112 Handle(StdSelect_BRepOwner) aCSolidOwner2 =
113 Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
114 isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
115 if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
116 isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
117 aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
120 return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;