]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ViewerPrs.cpp
Salome HOME
f11b3b0773ef0330cb50669abf288b9dbd95a923
[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()
12 {
13
14 }
15
16 ModuleBase_ViewerPrs::ModuleBase_ViewerPrs(ObjectPtr theResult, 
17                                            const GeomShapePtr& theShape, 
18                                            Handle_SelectMgr_EntityOwner theOwner) 
19 : myResult(theResult),
20   myShape(theShape),
21   myOwner(theOwner)
22 {
23 }
24
25 ModuleBase_ViewerPrs::~ModuleBase_ViewerPrs()
26 {
27 }
28
29 bool ModuleBase_ViewerPrs::operator==(const ModuleBase_ViewerPrs& thePrs)
30 {
31   bool isEqualResult = (myResult.get() == thePrs.object().get());
32   bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
33                        (myShape.get() && myShape->isEqual(thePrs.shape()));
34   bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
35
36   bool isEqualOwner = (myOwner.Access() == thePrs.owner().Access());
37   if (isEqualResult && isEqualShape && isEqualIO &&
38       !isEqualOwner) { /// owners are different
39     // as we might loading object with the same shape in different modes like
40     // "objects" and "other", it is possible that two owners are created linked
41     // to one shape. We should accept such ViewerPrs as equal to current in order
42     // to do not use the same <result, shape> twice
43     Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
44     Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
45     if (!anOwner1.IsNull() && !anOwner2.IsNull())
46       isEqualOwner = anOwner1->Shape() == anOwner2->Shape();
47   }
48
49   if (isEqualResult && isEqualShape &&
50       !isEqualIO) { /// AIS are different
51     // check that the owner is a fictive owner for compsolid object, created in the
52     // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
53     // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
54     // as they use the same shape and result(of compsolid)
55     Handle(ModuleBase_BRepOwner) aCSolidOwner1 = Handle(ModuleBase_BRepOwner)::DownCast(myOwner);
56     Handle(ModuleBase_BRepOwner) aCSolidOwner2 = Handle(ModuleBase_BRepOwner)::DownCast(thePrs.owner());
57     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
58     if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
59       isEqualOwner = aCSolidOwner1->Shape() == aCSolidOwner1->Shape();
60   }
61
62   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
63 }