0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / DDocStd / DDocStd.cxx
1 // Created on: 2000-03-01
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <DDocStd.hxx>
17
18 #include <DDocStd_DrawDocument.hxx>
19 #include <Draw.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <Standard_GUID.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_Tool.hxx>
25 #include <TDocStd_Application.hxx>
26 #include <TDocStd_Document.hxx>
27
28 #include <StdLDrivers.hxx>
29 #include <BinLDrivers.hxx>
30 #include <XmlLDrivers.hxx>
31 #include <StdDrivers.hxx>
32 #include <BinDrivers.hxx>
33 #include <XmlDrivers.hxx>
34
35 //=======================================================================
36 //function : Find
37 //purpose  : 
38 //=======================================================================
39
40 const Handle(TDocStd_Application)& DDocStd::GetApplication()
41 {
42   static Handle(TDocStd_Application) anApp;
43   if (anApp.IsNull())
44   {
45     anApp = new TDocStd_Application;
46
47     // Initialize standard document formats at creation - they should
48     // be available even if this DRAW plugin is not loaded by pload command
49     StdLDrivers::DefineFormat(anApp);
50     BinLDrivers::DefineFormat(anApp);
51     XmlLDrivers::DefineFormat(anApp);
52     StdDrivers::DefineFormat(anApp);
53     BinDrivers::DefineFormat(anApp);
54     XmlDrivers::DefineFormat(anApp);
55   }
56   return anApp;
57 }
58
59
60 //=======================================================================
61 //function : GetDocument
62 //purpose  : 
63 //=======================================================================
64
65 Standard_Boolean DDocStd::GetDocument (Standard_CString&         Name,
66                                        Handle(TDocStd_Document)& DOC,
67                                        const Standard_Boolean    Complain)
68 {
69   Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (Draw::GetExisting (Name));
70   if (DD.IsNull()) {
71     if (Complain) std::cout << Name << " is not a Document" << std::endl; 
72     return Standard_False;
73   }
74   Handle(TDocStd_Document) STDDOC = DD->GetDocument();
75   if (!STDDOC.IsNull()) {
76     DOC = STDDOC;
77     return Standard_True;
78   }
79   if (Complain) std::cout << Name << " is not a CAF Document" << std::endl; 
80   return Standard_False;
81 }
82
83
84 //=======================================================================
85 //function : Label
86 //purpose  : try to retrieve a label 
87 //=======================================================================
88
89 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
90                                 const Standard_CString  Entry,
91                                 TDF_Label& Label,   
92                                 const Standard_Boolean  Complain)
93 {
94   Label.Nullify();
95   TDF_Tool::Label(D->GetData(),Entry,Label,Standard_False);
96   if (Label.IsNull() && Complain) std::cout<<"No label for entry "<<Entry<<std::endl;
97   return !Label.IsNull();
98 }
99
100 //=======================================================================
101 //function : Find
102 //purpose  : Try to retrieve an attribute.
103 //=======================================================================
104
105 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
106                                 const Standard_CString  Entry,
107                                 const Standard_GUID&    ID,
108                                 Handle(TDF_Attribute)&  A,
109                                 const Standard_Boolean  Complain) 
110 {
111   TDF_Label L;
112   if (Find(D,Entry,L,Complain)) {
113     if (L.FindAttribute(ID,A)) return Standard_True;
114     if (Complain) std::cout <<"attribute not found for entry : "<< Entry <<std::endl; 
115   }
116   return Standard_False;   
117 }
118
119
120 //=======================================================================
121 //function : ReturnLabel
122 //purpose  : 
123 //=======================================================================
124  
125 Draw_Interpretor& DDocStd::ReturnLabel(Draw_Interpretor& di, const TDF_Label& L)
126 {
127   TCollection_AsciiString S;
128   TDF_Tool::Entry(L,S);
129   di << S.ToCString();
130   return di;
131 }
132
133 //=======================================================================
134 //function : AllCommands
135 //purpose  : 
136 //=======================================================================
137
138 void DDocStd::AllCommands(Draw_Interpretor& theCommands) 
139 {
140   static Standard_Boolean done = Standard_False;
141   if (done) return;
142   done = Standard_True;
143
144   // define commands
145   DDocStd::ApplicationCommands(theCommands);
146   DDocStd::DocumentCommands(theCommands);
147   DDocStd::ToolsCommands(theCommands);
148   DDocStd::MTMCommands(theCommands);
149   DDocStd::ShapeSchemaCommands(theCommands);
150 }