Salome HOME
Rectangle correction to have coincidence with point/line selected for the first point...
[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 TopoDS_Shape& 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.IsEqual(thePrs.shape()) == Standard_True;
33   bool isEqualIO = (myInteractive == thePrs.interactive()) == Standard_True;
34
35   bool isEqualOwner = (myOwner.Access() == thePrs.owner().Access());
36   if (isEqualResult && isEqualShape && isEqualIO &&
37       !isEqualOwner) { /// owners are different
38     // as we might loading object with the same shape in different modes like
39     // "objects" and "other", it is possible that two owners are created linked
40     // to one shape. We should accept such ViewerPrs as equal to current in order
41     // to do not use the same <result, shape> twice
42     Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(myOwner);
43     Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs.owner());
44     if (!anOwner1.IsNull() && !anOwner2.IsNull())
45       isEqualOwner = anOwner1->Shape() == 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(ModuleBase_BRepOwner) aCSolidOwner1 = Handle(ModuleBase_BRepOwner)::DownCast(myOwner);
55     Handle(ModuleBase_BRepOwner) aCSolidOwner2 = Handle(ModuleBase_BRepOwner)::DownCast(thePrs.owner());
56     isEqualIO = !aCSolidOwner1.IsNull() && !aCSolidOwner2.IsNull();
57     if (!aCSolidOwner1.IsNull() && !aCSolidOwner1.IsNull())
58       isEqualOwner = aCSolidOwner1->Shape() == aCSolidOwner1->Shape();
59   }
60
61   return isEqualResult && isEqualShape && isEqualOwner && isEqualIO;
62 }