0024624: Lost word in license statement in source files
[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 <TPrsStd_NamedShapeDriver.ixx>
17
18 #include <TDF_Label.hxx>
19 #include <TNaming_NamedShape.hxx>
20 #include <AIS_Shape.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <TDataStd.hxx>
23 #include <Standard_GUID.hxx>
24 #include <TPrsStd_DriverTable.hxx> 
25 #include <TNaming_Tool.hxx>
26 #include <TopLoc_Location.hxx>
27 #include <TColStd_ListOfInteger.hxx>
28 #include <TColStd_ListIteratorOfListOfInteger.hxx>
29 #include <PrsMgr_Presentation.hxx>
30 #include <Prs3d_Presentation.hxx>
31 #include <PrsMgr_Presentation3d.hxx>
32 #include <PrsMgr_PresentationManager3d.hxx>
33 #include <Geom_Transformation.hxx>
34
35 #undef OPTIM_UPDATE  // If this variable is defined there will be done
36 //                      more otimized update of AIS_Shape. If an object was
37 //                      erased in the viewer and it's location was changed
38 //                      but topological data wasn't then when displayed only 
39 //                      the object's presentation will be moved to new location
40 //                      without recompute. The shape in AIS_Shape will 
41 //                      be the previous one with the old location.       
42 //                      NOTE! After selection of sub shapes of the object
43 //                      they will have THE OLD LOCATION and it has to be
44 //                      compared with location of AIS_Shape that will contain
45 //                      the right location of shape. 
46  
47
48 //=======================================================================
49 //function :
50 //purpose  : 
51 //=======================================================================
52 TPrsStd_NamedShapeDriver::TPrsStd_NamedShapeDriver()
53 {
54 }
55
56 //=======================================================================
57 //function :
58 //purpose  : 
59 //=======================================================================
60 Standard_Boolean TPrsStd_NamedShapeDriver::Update (const TDF_Label& aLabel,
61                                                   Handle(AIS_InteractiveObject)& AIS) 
62 {
63   Handle(TNaming_NamedShape) NS;
64
65   if( !aLabel.FindAttribute(TNaming_NamedShape::GetID(), NS) )  {
66     return Standard_False;  
67   }
68
69   //TopoDS_Shape S = TNaming_Tool::CurrentShape (NS);
70   TopoDS_Shape S = TNaming_Tool::GetShape (NS);
71   if(S.IsNull()){ 
72     return Standard_False; 
73   }  
74   TopLoc_Location L  = S.Location();
75
76   Handle(AIS_Shape) AISShape;
77   if (AIS.IsNull()) AISShape = new AIS_Shape(S);
78   else {
79     AISShape = Handle(AIS_Shape)::DownCast(AIS);
80     if (AISShape.IsNull()) {
81       AISShape = new AIS_Shape(S);
82     }
83     else {
84       TopoDS_Shape oldShape = AISShape->Shape();
85       if(oldShape != S) {
86         AISShape->ResetLocation();
87
88 #ifdef OPTIM_UPDATE
89         Handle(AIS_InteractiveContext) ctx = AISShape->GetContext();
90         if(S.IsPartner(oldShape) && (!ctx.IsNull() && !ctx->IsDisplayed(AISShape))) {
91           if(L != oldShape.Location()) ctx->SetLocation(AISShape, L);
92         }
93         else {
94           AISShape->Set(S);
95           AISShape->UpdateSelection();
96           AISShape->SetToUpdate();        
97         }
98 #else
99         AISShape->Set(S);
100         AISShape->UpdateSelection();
101         AISShape->SetToUpdate();      
102 #endif
103       }
104     }
105
106     AISShape->SetInfiniteState(S.Infinite());
107   }
108   AIS = AISShape;
109   return Standard_True;
110  
111 }
112