0024047: Exception in TPrsStd_AISPresentation during destruction of TDocStd_Document
[occt.git] / src / TPrsStd / TPrsStd_NamedShapeDriver.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18// last modified by SRN 01/08/2000
19
20#include <TPrsStd_NamedShapeDriver.ixx>
21
22#include <TDF_Label.hxx>
23#include <TNaming_NamedShape.hxx>
24#include <AIS_Shape.hxx>
25#include <AIS_InteractiveContext.hxx>
26#include <TDataStd.hxx>
27#include <Standard_GUID.hxx>
28#include <TPrsStd_DriverTable.hxx>
29#include <TNaming_Tool.hxx>
30#include <TopLoc_Location.hxx>
31#include <TColStd_ListOfInteger.hxx>
32#include <TColStd_ListIteratorOfListOfInteger.hxx>
33#include <PrsMgr_Presentation.hxx>
34#include <Prs3d_Presentation.hxx>
35#include <PrsMgr_Presentation3d.hxx>
36#include <PrsMgr_PresentationManager3d.hxx>
37#include <Geom_Transformation.hxx>
38
39#undef OPTIM_UPDATE // If this variable is defined there will be done
40// more otimized update of AIS_Shape. If an object was
41// erased in the viewer and it's location was changed
42// but topological data wasn't then when displayed only
43// the object's presentation will be moved to new location
44// without recompute. The shape in AIS_Shape will
45// be the previous one with the old location.
46// NOTE! After selection of sub shapes of the object
47// they will have THE OLD LOCATION and it has to be
48// compared with location of AIS_Shape that will contain
49// the right location of shape.
50
51
52//=======================================================================
53//function :
54//purpose :
55//=======================================================================
56TPrsStd_NamedShapeDriver::TPrsStd_NamedShapeDriver()
57{
58}
59
60//=======================================================================
61//function :
62//purpose :
63//=======================================================================
64Standard_Boolean TPrsStd_NamedShapeDriver::Update (const TDF_Label& aLabel,
65 Handle(AIS_InteractiveObject)& AIS)
66{
67 Handle(TNaming_NamedShape) NS;
68
69 if( !aLabel.FindAttribute(TNaming_NamedShape::GetID(), NS) ) {
70 return Standard_False;
71 }
72
73 //TopoDS_Shape S = TNaming_Tool::CurrentShape (NS);
74 TopoDS_Shape S = TNaming_Tool::GetShape (NS);
75 if(S.IsNull()){
76 return Standard_False;
77 }
78 TopLoc_Location L = S.Location();
79
80 Handle(AIS_Shape) AISShape;
81 if (AIS.IsNull()) AISShape = new AIS_Shape(S);
82 else {
83 AISShape = Handle(AIS_Shape)::DownCast(AIS);
84 if (AISShape.IsNull()) {
85 AISShape = new AIS_Shape(S);
86 }
87 else {
88 TopoDS_Shape oldShape = AISShape->Shape();
89 if(oldShape != S) {
90 AISShape->ResetLocation();
91
92#ifdef OPTIM_UPDATE
93 Handle(AIS_InteractiveContext) ctx = AISShape->GetContext();
94 if(S.IsPartner(oldShape) && (!ctx.IsNull() && !ctx->IsDisplayed(AISShape))) {
95 if(L != oldShape.Location()) ctx->SetLocation(AISShape, L);
96 }
97 else {
98 AISShape->Set(S);
99 AISShape->UpdateSelection();
100 AISShape->SetToUpdate();
101 }
102#else
103 AISShape->Set(S);
104 AISShape->UpdateSelection();
105 AISShape->SetToUpdate();
106#endif
107 }
108 }
109
110 AISShape->SetInfiniteState(S.Infinite());
111 }
112 AIS = AISShape;
113 return Standard_True;
114
115}
116