Salome HOME
Issue #1505 Bug in parameters management (with parts not loaded)
[modules/shaper.git] / src / ModuleBase / ModuleBase_ViewerPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_ViewerPrs.cpp
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include "ModuleBase_ViewerPrs.h"
8
9 #include <ModuleBase_ResultPrs.h>
10
11 ModuleBase_ViewerPrs::ModuleBase_ViewerPrs(ObjectPtr theResult, 
12                                            const GeomShapePtr& theShape, 
13                                            Handle_SelectMgr_EntityOwner theOwner) 
14 : myResult(theResult),
15   myShape(theShape),
16   myOwner(theOwner)
17 {
18 }
19
20 ModuleBase_ViewerPrs::~ModuleBase_ViewerPrs()
21 {
22 }
23
24 bool ModuleBase_ViewerPrs::isEqual(ModuleBase_ViewerPrs* thePrs) const
25 {
26   if (!thePrs || thePrs->isEmpty())
27     return false;
28
29   bool isEqualResult = (myResult.get() == thePrs->object().get());
30   bool isEqualShape = (!myShape.get() && !thePrs->shape().get()) ||
31                        (myShape.get() && myShape->isEqual(thePrs->shape()));
32   bool isEqualIO = (myInteractive == thePrs->interactive()) == Standard_True;
33
34   bool isEqualOwner = (myOwner.Access() == thePrs->owner().Access());
35   if (isEqualResult && isEqualShape && isEqualIO &&
36       !isEqualOwner) { /// owners are different
37     // as we might loading object with the same shape in different modes like
38     // "objects" and "other", it is possible that two owners are created linked
39     // to one shape. We should accept such ViewerPrs as equal to current in order
40     // to do not use the same <result, shape> twice
41     Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
42     Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
43     if (!anOwner1.IsNull() && !anOwner2.IsNull())
44       isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
45                       anOwner1->Shape().IsEqual(anOwner2->Shape());
46   }
47
48   if (isEqualResult && isEqualShape &&
49       !isEqualIO) { /// AIS are different
50     // check that the owner is a fictive owner for compsolid object, created in the
51     // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
52     // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
53     // as they use the same shape and result(of compsolid)
54     Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
55     Handle(StdSelect_BRepOwner) aCSolidOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
56     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
57     if (!aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull())
58       isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
59                       aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
60   }
61
62   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
63 }
64
65 bool ModuleBase_ViewerPrs::operator==(const ModuleBase_ViewerPrs& thePrs)
66 {
67   if (thePrs.isEmpty())
68     return false;
69
70   bool isEqualResult = (myResult.get() == thePrs.object().get());
71   bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
72                        (myShape.get() && myShape->isEqual(thePrs.shape()));
73   bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
74
75   bool isEqualOwner = (myOwner.Access() == thePrs.owner().Access());
76   if (isEqualResult && isEqualShape && isEqualIO &&
77       !isEqualOwner) { /// owners are different
78     // as we might loading object with the same shape in different modes like
79     // "objects" and "other", it is possible that two owners are created linked
80     // to one shape. We should accept such ViewerPrs as equal to current in order
81     // to do not use the same <result, shape> twice
82     Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
83     Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
84     if (!anOwner1.IsNull() && !anOwner2.IsNull())
85       isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
86                       anOwner1->Shape().IsEqual(anOwner2->Shape());
87   }
88
89   if (isEqualResult && isEqualShape &&
90       !isEqualIO) { /// AIS are different
91     // check that the owner is a fictive owner for compsolid object, created in the
92     // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
93     // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
94     // as they use the same shape and result(of compsolid)
95     Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
96     Handle(StdSelect_BRepOwner) aCSolidOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
97     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
98     if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
99       isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
100                       aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
101   }
102
103   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
104 }