]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ViewerPrs.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[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.get() == thePrs->owner().get();
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 =
56       Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
57     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
58     if (!aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull())
59       isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
60                       aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
61   }
62
63   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
64 }
65
66 bool ModuleBase_ViewerPrs::operator==(const ModuleBase_ViewerPrs& thePrs)
67 {
68   if (thePrs.isEmpty())
69     return false;
70
71   bool isEqualResult = (myResult.get() == thePrs.object().get());
72   bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
73                        (myShape.get() && myShape->isEqual(thePrs.shape()));
74   bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
75
76   bool isEqualOwner = myOwner.get() == thePrs.owner().get();
77   if (isEqualResult && isEqualShape && isEqualIO &&
78       !isEqualOwner) { /// owners are different
79     // as we might loading object with the same shape in different modes like
80     // "objects" and "other", it is possible that two owners are created linked
81     // to one shape. We should accept such ViewerPrs as equal to current in order
82     // to do not use the same <result, shape> twice
83     Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
84     Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
85     if (!anOwner1.IsNull() && !anOwner2.IsNull())
86       isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
87                       anOwner1->Shape().IsEqual(anOwner2->Shape());
88   }
89
90   if (isEqualResult && isEqualShape &&
91       !isEqualIO) { /// AIS are different
92     // check that the owner is a fictive owner for compsolid object, created in the
93     // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
94     // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
95     // as they use the same shape and result(of compsolid)
96     Handle(StdSelect_BRepOwner) aCSolidOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
97     Handle(StdSelect_BRepOwner) aCSolidOwner2 =
98       Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
99     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
100     if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
101       isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
102                       aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
103   }
104
105   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
106 }