0024837: Visualization - revise design and implementation of connected Interactive...
[occt.git] / src / TPrsStd / TPrsStd_NamedShapeDriver.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 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>
af324faa 31#include <PrsMgr_PresentationManager.hxx>
7fd59977 32#include <Geom_Transformation.hxx>
33
34#undef OPTIM_UPDATE // If this variable is defined there will be done
35// more otimized update of AIS_Shape. If an object was
36// erased in the viewer and it's location was changed
37// but topological data wasn't then when displayed only
38// the object's presentation will be moved to new location
39// without recompute. The shape in AIS_Shape will
40// be the previous one with the old location.
41// NOTE! After selection of sub shapes of the object
42// they will have THE OLD LOCATION and it has to be
43// compared with location of AIS_Shape that will contain
44// the right location of shape.
45
46
47//=======================================================================
48//function :
49//purpose :
50//=======================================================================
51TPrsStd_NamedShapeDriver::TPrsStd_NamedShapeDriver()
52{
53}
54
55//=======================================================================
56//function :
57//purpose :
58//=======================================================================
59Standard_Boolean TPrsStd_NamedShapeDriver::Update (const TDF_Label& aLabel,
60 Handle(AIS_InteractiveObject)& AIS)
61{
62 Handle(TNaming_NamedShape) NS;
63
64 if( !aLabel.FindAttribute(TNaming_NamedShape::GetID(), NS) ) {
65 return Standard_False;
66 }
67
68 //TopoDS_Shape S = TNaming_Tool::CurrentShape (NS);
69 TopoDS_Shape S = TNaming_Tool::GetShape (NS);
70 if(S.IsNull()){
71 return Standard_False;
72 }
73 TopLoc_Location L = S.Location();
74
75 Handle(AIS_Shape) AISShape;
76 if (AIS.IsNull()) AISShape = new AIS_Shape(S);
77 else {
78 AISShape = Handle(AIS_Shape)::DownCast(AIS);
79 if (AISShape.IsNull()) {
80 AISShape = new AIS_Shape(S);
81 }
82 else {
83 TopoDS_Shape oldShape = AISShape->Shape();
84 if(oldShape != S) {
0717ddc1 85 AISShape->ResetTransformation();
7fd59977 86
87#ifdef OPTIM_UPDATE
88 Handle(AIS_InteractiveContext) ctx = AISShape->GetContext();
89 if(S.IsPartner(oldShape) && (!ctx.IsNull() && !ctx->IsDisplayed(AISShape))) {
90 if(L != oldShape.Location()) ctx->SetLocation(AISShape, L);
91 }
92 else {
93 AISShape->Set(S);
94 AISShape->UpdateSelection();
95 AISShape->SetToUpdate();
96 }
97#else
98 AISShape->Set(S);
99 AISShape->UpdateSelection();
100 AISShape->SetToUpdate();
101#endif
102 }
103 }
104
105 AISShape->SetInfiniteState(S.Infinite());
106 }
107 AIS = AISShape;
108 return Standard_True;
109
110}
111