0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / TPrsStd / TPrsStd_NamedShapeDriver.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 // last modified by SRN 01/08/2000    
15
16 #include <AIS_InteractiveContext.hxx>
17 #include <AIS_InteractiveObject.hxx>
18 #include <AIS_Shape.hxx>
19 #include <Geom_Transformation.hxx>
20 #include <Prs3d_Presentation.hxx>
21 #include <PrsMgr_Presentation.hxx>
22 #include <PrsMgr_PresentationManager.hxx>
23 #include <Standard_GUID.hxx>
24 #include <Standard_Type.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_ListOfInteger.hxx>
27 #include <TDataStd.hxx>
28 #include <TDF_Label.hxx>
29 #include <TNaming_NamedShape.hxx>
30 #include <TNaming_Tool.hxx>
31 #include <TopLoc_Location.hxx>
32 #include <TPrsStd_DriverTable.hxx>
33 #include <TPrsStd_NamedShapeDriver.hxx>
34
35 IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_NamedShapeDriver,TPrsStd_Driver)
36
37 #undef OPTIM_UPDATE  // If this variable is defined there will be done
38 //                      more otimized update of AIS_Shape. If an object was
39 //                      erased in the viewer and it's location was changed
40 //                      but topological data wasn't then when displayed only 
41 //                      the object's presentation will be moved to new location
42 //                      without recompute. The shape in AIS_Shape will 
43 //                      be the previous one with the old location.       
44 //                      NOTE! After selection of sub shapes of the object
45 //                      they will have THE OLD LOCATION and it has to be
46 //                      compared with location of AIS_Shape that will contain
47 //                      the right location of shape. 
48  
49
50 //=======================================================================
51 //function :
52 //purpose  : 
53 //=======================================================================
54 TPrsStd_NamedShapeDriver::TPrsStd_NamedShapeDriver()
55 {
56 }
57
58 //=======================================================================
59 //function :
60 //purpose  : 
61 //=======================================================================
62 Standard_Boolean TPrsStd_NamedShapeDriver::Update (const TDF_Label& aLabel,
63                                                   Handle(AIS_InteractiveObject)& AIS) 
64 {
65   Handle(TNaming_NamedShape) NS;
66
67   if( !aLabel.FindAttribute(TNaming_NamedShape::GetID(), NS) )  {
68     return Standard_False;  
69   }
70
71   //TopoDS_Shape S = TNaming_Tool::CurrentShape (NS);
72   TopoDS_Shape S = TNaming_Tool::GetShape (NS);
73   if(S.IsNull()){ 
74     return Standard_False; 
75   }  
76   TopLoc_Location L  = S.Location();
77
78   Handle(AIS_Shape) AISShape;
79   if (AIS.IsNull()) AISShape = new AIS_Shape(S);
80   else {
81     AISShape = Handle(AIS_Shape)::DownCast(AIS);
82     if (AISShape.IsNull()) {
83       AISShape = new AIS_Shape(S);
84     }
85     else {
86       TopoDS_Shape oldShape = AISShape->Shape();
87       if(oldShape != S) {
88         AISShape->ResetTransformation();
89
90 #ifdef OPTIM_UPDATE
91         Handle(AIS_InteractiveContext) ctx = AISShape->GetContext();
92         if(S.IsPartner(oldShape) && (!ctx.IsNull() && !ctx->IsDisplayed(AISShape))) {
93           if(L != oldShape.Location()) ctx->SetLocation(AISShape, L);
94         }
95         else {
96           AISShape->Set(S);
97           AISShape->UpdateSelection();
98           AISShape->SetToUpdate();        
99         }
100 #else
101         AISShape->Set(S);
102         AISShape->UpdateSelection();
103         AISShape->SetToUpdate();      
104 #endif
105       }
106     }
107
108     AISShape->SetInfiniteState(S.Infinite());
109   }
110   AIS = AISShape;
111   return Standard_True;
112  
113 }
114