Salome HOME
#1404 Random crash with Shaper: AIS presentations: operation prs, result sketch prs...
[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::operator==(const ModuleBase_ViewerPrs& thePrs)
25 {
26   bool isEqualResult = (myResult.get() == thePrs.object().get());
27   bool isEqualShape = (!myShape.get() && !thePrs.shape().get()) ||
28                        (myShape.get() && myShape->isEqual(thePrs.shape()));
29   bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
30
31   bool isEqualOwner = (myOwner.Access() == thePrs.owner().Access());
32   if (isEqualResult && isEqualShape && isEqualIO &&
33       !isEqualOwner) { /// owners are different
34     // as we might loading object with the same shape in different modes like
35     // "objects" and "other", it is possible that two owners are created linked
36     // to one shape. We should accept such ViewerPrs as equal to current in order
37     // to do not use the same <result, shape> twice
38     Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
39     Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
40     if (!anOwner1.IsNull() && !anOwner2.IsNull())
41       isEqualOwner = (anOwner1->Shape().IsNull() && anOwner2->Shape().IsNull()) ||
42                       anOwner1->Shape().IsEqual(anOwner2->Shape());
43   }
44
45   if (isEqualResult && isEqualShape &&
46       !isEqualIO) { /// AIS are different
47     // check that the owner is a fictive owner for compsolid object, created in the
48     // ComputeSelection of ModuleBase_ResultPrs. A new owner is created there for each subsolid
49     // and set in the sub-solid AIS. ViewerPrs of these fictive owners are accepted as equal
50     // as they use the same shape and result(of compsolid)
51     Handle(ModuleBase_BRepOwner) aCSolidOwner1 = Handle(ModuleBase_BRepOwner)::DownCast(myOwner);
52     Handle(ModuleBase_BRepOwner) aCSolidOwner2 = Handle(ModuleBase_BRepOwner)::DownCast(thePrs.owner());
53     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
54     if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
55       isEqualOwner = (aCSolidOwner1->Shape().IsNull() && aCSolidOwner2->Shape().IsNull()) ||
56                       aCSolidOwner1->Shape().IsEqual(aCSolidOwner2->Shape());
57   }
58
59   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
60 }