Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-08-04 |
2 | // Created by: Pavel TELKOV | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
7fd59977 | 16 | |
7fd59977 | 17 | #include <AIS_InteractiveContext.hxx> |
42cf5bc1 | 18 | #include <AIS_InteractiveObject.hxx> |
19 | #include <AIS_Trihedron.hxx> | |
20 | #include <Aspect_TypeOfLine.hxx> | |
21 | #include <DBRep.hxx> | |
7fd59977 | 22 | #include <DDF_Browser.hxx> |
23 | #include <DDocStd.hxx> | |
24 | #include <DDocStd_DrawDocument.hxx> | |
42cf5bc1 | 25 | #include <Draw.hxx> |
26 | #include <Draw_PluginMacro.hxx> | |
27 | #include <Geom_Axis2Placement.hxx> | |
28 | #include <Prs3d_Drawer.hxx> | |
29 | #include <Prs3d_LineAspect.hxx> | |
30 | #include <Quantity_Color.hxx> | |
02a0b964 | 31 | #include <STEPCAFControl_Controller.hxx> |
42cf5bc1 | 32 | #include <TCollection_AsciiString.hxx> |
33 | #include <TCollection_ExtendedString.hxx> | |
34 | #include <TCollection_HAsciiString.hxx> | |
35 | #include <TColStd_HArray1OfInteger.hxx> | |
36 | #include <TColStd_HArray1OfReal.hxx> | |
37 | #include <TColStd_HSequenceOfExtendedString.hxx> | |
38 | #include <TDataStd_AsciiString.hxx> | |
39 | #include <TDataStd_ByteArray.hxx> | |
40 | #include <TDataStd_Comment.hxx> | |
41 | #include <TDataStd_Integer.hxx> | |
42 | #include <TDataStd_IntegerArray.hxx> | |
43 | #include <TDataStd_Name.hxx> | |
44 | #include <TDataStd_Real.hxx> | |
45 | #include <TDataStd_RealArray.hxx> | |
46 | #include <TDataStd_TreeNode.hxx> | |
47 | #include <TDataStd_UAttribute.hxx> | |
48 | #include <TDF_AttributeIterator.hxx> | |
ab1f4580 | 49 | #include <TDF_ChildIterator.hxx> |
7fd59977 | 50 | #include <TDF_Data.hxx> |
51 | #include <TDF_LabelSequence.hxx> | |
f767df4e | 52 | #include <TDF_Reference.hxx> |
42cf5bc1 | 53 | #include <TDF_Tool.hxx> |
6fe96f84 | 54 | #include <TDocStd_Application.hxx> |
7fd59977 | 55 | #include <TDocStd_Document.hxx> |
42cf5bc1 | 56 | #include <TDocStd_Owner.hxx> |
7fd59977 | 57 | #include <TNaming_NamedShape.hxx> |
42cf5bc1 | 58 | #include <TopoDS_Shape.hxx> |
7fd59977 | 59 | #include <TPrsStd_AISPresentation.hxx> |
7fd59977 | 60 | #include <TPrsStd_AISViewer.hxx> |
6fe96f84 | 61 | #include <TPrsStd_DriverTable.hxx> |
42cf5bc1 | 62 | #include <TPrsStd_NamedShapeDriver.hxx> |
63 | #include <V3d_View.hxx> | |
64 | #include <V3d_Viewer.hxx> | |
65 | #include <ViewerTest.hxx> | |
ab1f4580 | 66 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 67 | #include <XCAFDoc.hxx> |
7fd59977 | 68 | #include <XCAFDoc_Area.hxx> |
69 | #include <XCAFDoc_Centroid.hxx> | |
42cf5bc1 | 70 | #include <XCAFDoc_Color.hxx> |
7fd59977 | 71 | #include <XCAFDoc_ColorTool.hxx> |
42cf5bc1 | 72 | #include <XCAFDoc_DimTol.hxx> |
9ebaae37 | 73 | #include <XCAFDoc_Dimension.hxx> |
74 | #include <XCAFDoc_Datum.hxx> | |
75 | #include <XCAFDoc_GeomTolerance.hxx> | |
7fd59977 | 76 | #include <XCAFDoc_DocumentTool.hxx> |
77 | #include <XCAFDoc_GraphNode.hxx> | |
78 | #include <XCAFDoc_LayerTool.hxx> | |
7fd59977 | 79 | #include <XCAFDoc_Material.hxx> |
42cf5bc1 | 80 | #include <XCAFDoc_ShapeTool.hxx> |
81 | #include <XCAFDoc_Volume.hxx> | |
82 | #include <XCAFPrs.hxx> | |
ab1f4580 | 83 | #include <XCAFPrs_AISObject.hxx> |
7fd59977 | 84 | #include <XCAFPrs_Driver.hxx> |
42cf5bc1 | 85 | #include <XDEDRAW.hxx> |
7fd59977 | 86 | #include <XDEDRAW_Colors.hxx> |
42cf5bc1 | 87 | #include <XDEDRAW_Common.hxx> |
7fd59977 | 88 | #include <XDEDRAW_Layers.hxx> |
89 | #include <XDEDRAW_Props.hxx> | |
42cf5bc1 | 90 | #include <XDEDRAW_Shapes.hxx> |
9ebaae37 | 91 | #include <XDEDRAW_GDTs.hxx> |
2df785d7 | 92 | #include <XDEDRAW_Views.hxx> |
024d6f77 | 93 | #include <XDEDRAW_Notes.hxx> |
42cf5bc1 | 94 | #include <XSDRAW.hxx> |
7fd59977 | 95 | #include <XSDRAWIGES.hxx> |
96 | #include <XSDRAWSTEP.hxx> | |
a2d5ab2e | 97 | |
6fe96f84 | 98 | #include <BinXCAFDrivers.hxx> |
99 | #include <XmlXCAFDrivers.hxx> | |
100 | ||
42cf5bc1 | 101 | #include <stdio.h> |
7fd59977 | 102 | |
103 | //======================================================================= | |
104 | // Section: General commands | |
105 | //======================================================================= | |
106 | ||
107 | //======================================================================= | |
108 | //function : newDoc | |
109 | //purpose : | |
110 | //======================================================================= | |
111 | static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
112 | { | |
586db386 | 113 | if (argc < 2) {di<<"Give document name\n";return 1;} |
7fd59977 | 114 | |
115 | Handle(TDocStd_Document) D; | |
116 | Handle(DDocStd_DrawDocument) DD; | |
6fe96f84 | 117 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 118 | |
119 | if (!DDocStd::GetDocument(argv[1],D,Standard_False)) { | |
fff263bd | 120 | A->NewDocument( "BinXCAF" ,D); |
7fd59977 | 121 | DD = new DDocStd_DrawDocument(D); |
122 | TDataStd_Name::Set(D->GetData()->Root(),argv[1]); | |
123 | Draw::Set(argv[1],DD); | |
586db386 | 124 | di << "document " << argv[1] << " created\n"; |
7fd59977 | 125 | //DDocStd::ReturnLabel(di,D->Main()); |
126 | } | |
586db386 | 127 | else di << argv[1] << " is already a document\n"; |
7fd59977 | 128 | |
129 | return 0; | |
130 | } | |
131 | ||
132 | ||
133 | //======================================================================= | |
134 | //function : saveDoc | |
135 | //purpose : | |
136 | //======================================================================= | |
137 | static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
138 | { | |
139 | Handle(TDocStd_Document) D; | |
6fe96f84 | 140 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 141 | |
142 | if (argc == 1) { | |
143 | if (A->NbDocuments() < 1) return 1; | |
144 | A->GetDocument(1, D); | |
145 | } | |
146 | else { | |
147 | if (!DDocStd::GetDocument(argv[1],D)) return 1; | |
148 | } | |
149 | ||
61887a4a | 150 | PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull; |
151 | if (argc == 3) | |
152 | { | |
7fd59977 | 153 | TCollection_ExtendedString path (argv[2]); |
61887a4a | 154 | aStatus = A->SaveAs (D, path); |
7fd59977 | 155 | } |
61887a4a | 156 | else if (!D->IsSaved()) |
157 | { | |
158 | std::cout << "Storage error: this document has never been saved\n"; | |
7fd59977 | 159 | return 1; |
160 | } | |
61887a4a | 161 | else |
162 | { | |
163 | aStatus = A->Save(D); | |
164 | } | |
165 | ||
166 | switch (aStatus) | |
167 | { | |
168 | case PCDM_SS_OK: | |
169 | break; | |
170 | case PCDM_SS_DriverFailure: | |
171 | di << "Storage error: driver failure\n"; | |
172 | break; | |
173 | case PCDM_SS_WriteFailure: | |
174 | di << "Storage error: write failure\n"; | |
175 | break; | |
176 | case PCDM_SS_Failure: | |
177 | di << "Storage error: general failure\n"; | |
178 | break; | |
179 | case PCDM_SS_Doc_IsNull: | |
180 | di << "Storage error: document is NULL\n"; | |
181 | break; | |
182 | case PCDM_SS_No_Obj: | |
183 | di << "Storage error: no object\n"; | |
184 | break; | |
185 | case PCDM_SS_Info_Section_Error: | |
186 | di << "Storage error: section error\n"; | |
187 | break; | |
6d8f9f4a | 188 | case PCDM_SS_UserBreak: |
189 | di << "Storage error: user break\n"; | |
190 | break; | |
61887a4a | 191 | } |
192 | ||
7fd59977 | 193 | return 0; |
194 | } | |
195 | ||
02a0b964 | 196 | //======================================================================= |
197 | //function : openDoc | |
198 | //purpose : | |
199 | //======================================================================= | |
200 | static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
201 | { | |
202 | Handle(TDocStd_Document) D; | |
203 | Handle(DDocStd_DrawDocument) DD; | |
6fe96f84 | 204 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
02a0b964 | 205 | |
206 | if ( argc != 3 ) | |
207 | { | |
586db386 | 208 | di << "invalid number of arguments. Usage:\t XOpen filename docname\n"; |
02a0b964 | 209 | return 1; |
210 | } | |
211 | ||
212 | Standard_CString Filename = argv[1]; | |
213 | Standard_CString DocName = argv[2]; | |
214 | ||
215 | if ( DDocStd::GetDocument(DocName, D, Standard_False) ) | |
216 | { | |
586db386 | 217 | di << "document with name " << DocName << " already exists\n"; |
02a0b964 | 218 | return 1; |
219 | } | |
220 | ||
221 | if ( A->Open(Filename, D) != PCDM_RS_OK ) | |
222 | { | |
586db386 | 223 | di << "cannot open XDE document\n"; |
02a0b964 | 224 | return 1; |
225 | } | |
226 | ||
227 | DD = new DDocStd_DrawDocument(D); | |
228 | TDataStd_Name::Set(D->GetData()->Root(), DocName); | |
229 | Draw::Set(DocName, DD); | |
230 | ||
586db386 | 231 | di << "document " << DocName << " opened\n"; |
02a0b964 | 232 | |
233 | return 0; | |
234 | } | |
7fd59977 | 235 | |
236 | //======================================================================= | |
237 | //function : dump | |
238 | //purpose : | |
239 | //======================================================================= | |
240 | static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
241 | { | |
242 | if (argc<2) { | |
586db386 | 243 | di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n"; |
7fd59977 | 244 | return 1; |
245 | } | |
246 | Handle(TDocStd_Document) Doc; | |
247 | DDocStd::GetDocument(argv[1], Doc); | |
586db386 | 248 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 | 249 | |
250 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); | |
251 | Standard_Boolean deep = Standard_False; | |
91322f44 | 252 | if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True; |
0cc44c47 | 253 | Standard_SStream aDumpLog; |
254 | myAssembly->Dump(aDumpLog, deep); | |
255 | di<<aDumpLog; | |
7fd59977 | 256 | return 0; |
257 | } | |
258 | ||
259 | ||
260 | //======================================================================= | |
261 | //function : StatAssembly | |
262 | //purpose : recursive part of statistics | |
263 | //======================================================================= | |
264 | ||
265 | static void StatAssembly(const TDF_Label L, | |
266 | const Standard_Integer level, | |
267 | Handle(TColStd_HArray1OfInteger) &HAI, | |
268 | Standard_Integer &NbCentroidProp, | |
269 | Standard_Integer &NbVolumeProp, | |
270 | Standard_Integer &NbAreaProp, | |
271 | Standard_Integer &NbShapesWithName, | |
272 | Standard_Integer &NbShapesWithColor, | |
273 | Standard_Integer &NbShapesWithLayer, | |
274 | Handle(TDocStd_Document) &aDoc, | |
275 | Standard_Boolean &PrintStructMode, | |
276 | Draw_Interpretor& di) | |
277 | { | |
278 | if(PrintStructMode) { | |
279 | for(Standard_Integer j=0; j<=level; j++) | |
280 | di<<" "; | |
281 | } | |
282 | TCollection_AsciiString Entry; | |
283 | TDF_Tool::Entry(L, Entry); | |
284 | if(PrintStructMode) di<<Entry.ToCString(); | |
285 | ||
286 | Handle(TDataStd_Name) Name; | |
287 | if(L.FindAttribute(TDataStd_Name::GetID(), Name)) { | |
288 | NbShapesWithName++; | |
289 | if(PrintStructMode) { | |
290 | TCollection_AsciiString AsciiStringName(Name->Get(),'?'); | |
291 | di<<" "<<AsciiStringName.ToCString()<<" has attributes: "; | |
292 | } | |
293 | } | |
294 | else { | |
295 | if(PrintStructMode) di<<" NoName has attributes: "; | |
296 | } | |
297 | ||
298 | Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid); | |
299 | if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) { | |
300 | if(PrintStructMode) di<<"Centroid "; | |
301 | NbCentroidProp++; | |
302 | } | |
303 | Standard_Real tmp; | |
304 | if(XCAFDoc_Volume::Get(L,tmp)) { | |
305 | if(PrintStructMode) di<<"Volume("<<tmp<<") "; | |
306 | NbVolumeProp++; | |
307 | } | |
308 | if(XCAFDoc_Area::Get(L,tmp)) { | |
309 | if(PrintStructMode) di<<"Area("<<tmp<<") "; | |
310 | NbAreaProp++; | |
311 | } | |
312 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main()); | |
08b183fe | 313 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main()); |
973d410e | 314 | Quantity_ColorRGBA col; |
7fd59977 | 315 | Standard_Boolean IsColor = Standard_False; |
08b183fe | 316 | Standard_Boolean IsByLayer = Standard_False; |
7fd59977 | 317 | if(CTool->GetColor(L,XCAFDoc_ColorGen,col)) |
318 | IsColor = Standard_True; | |
319 | else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col)) | |
320 | IsColor = Standard_True; | |
321 | else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col)) | |
322 | IsColor = Standard_True; | |
08b183fe | 323 | else if(CTool->IsColorByLayer(L)) |
324 | IsByLayer = Standard_True; | |
325 | if(IsColor || IsByLayer) { | |
326 | if(IsByLayer) | |
327 | { | |
328 | Handle(TColStd_HSequenceOfExtendedString) aLayerS; | |
329 | LTool->GetLayers(L, aLayerS); | |
330 | // Currently for DXF pnly, thus | |
331 | // only 1 Layer should be. | |
332 | if(aLayerS->Length() == 1) | |
333 | { | |
334 | TDF_Label aLayer = LTool->FindLayer (aLayerS->First()); | |
335 | Quantity_ColorRGBA aColor; | |
336 | if (CTool->GetColor (aLayer, XCAFDoc_ColorGen, aColor)) | |
337 | { | |
338 | TCollection_AsciiString aColorName = aColor.GetRGB().StringName(aColor.GetRGB().Name()); | |
339 | di<<"Color(" << aColorName.ToCString() << ") "; | |
340 | } | |
341 | else | |
342 | { | |
343 | di<<"Color(ByLayer) "; | |
344 | } | |
345 | } | |
346 | NbShapesWithColor++; | |
347 | } | |
348 | else | |
349 | { | |
350 | TCollection_AsciiString Entry1; | |
351 | Entry1 = col.GetRGB().StringName(col.GetRGB().Name()); | |
352 | if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<" "<<col.Alpha()<<") "; | |
353 | NbShapesWithColor++; | |
354 | } | |
7fd59977 | 355 | } |
7fd59977 | 356 | Handle(TColStd_HSequenceOfExtendedString) aLayerS; |
357 | LTool->GetLayers(L, aLayerS); | |
358 | if(!aLayerS.IsNull() && aLayerS->Length()>0) { | |
359 | if(PrintStructMode) { | |
360 | di<<"Layer("; | |
361 | for(Standard_Integer i=1; i<=aLayerS->Length(); i++) { | |
362 | TCollection_AsciiString Entry2(aLayerS->Value(i),'?'); | |
363 | if(i==1) | |
364 | di<<"\""<<Entry2.ToCString()<<"\""; | |
365 | else | |
586db386 | 366 | di<<" \""<<Entry2.ToCString()<<"\""; |
7fd59977 | 367 | } |
368 | di<<") "; | |
369 | } | |
370 | NbShapesWithLayer++; | |
371 | } | |
372 | if(PrintStructMode) di<<"\n"; | |
373 | ||
374 | HAI->SetValue(level, HAI->Value(level)+1 ); | |
375 | if(L.HasChild()) { | |
376 | for(Standard_Integer i=1; i<=L.NbChildren(); i++) { | |
377 | StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp, | |
378 | NbAreaProp, NbShapesWithName, NbShapesWithColor, | |
379 | NbShapesWithLayer, aDoc, PrintStructMode, di); | |
380 | } | |
381 | } | |
382 | ||
383 | } | |
384 | ||
385 | ||
386 | //======================================================================= | |
387 | //function : statdoc | |
388 | //purpose : | |
389 | //======================================================================= | |
390 | static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
391 | { | |
392 | if (argc<2) { | |
586db386 | 393 | di<<"Use: "<<argv[0]<<" Doc \n"; |
7fd59977 | 394 | return 1; |
395 | } | |
396 | Handle(TDocStd_Document) Doc; | |
397 | DDocStd::GetDocument(argv[1], Doc); | |
586db386 | 398 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 | 399 | |
400 | Standard_Boolean PrintStructMode = (argc==3); | |
401 | Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); | |
402 | ||
403 | TDF_LabelSequence SeqLabels; | |
404 | aTool->GetShapes(SeqLabels); | |
405 | if(SeqLabels.Length()<=0) return 0; | |
586db386 | 406 | if(PrintStructMode) di<<"\nStructure of shapes in the document:\n"; |
7fd59977 | 407 | Standard_Integer level=0; |
408 | Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0; | |
409 | Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0; | |
410 | Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20); | |
411 | Standard_Integer i=0; | |
412 | for(i=0; i<=20; i++) HAI->SetValue(i,0); | |
413 | for(i=1; i<=SeqLabels.Length(); i++) { | |
414 | StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp, | |
415 | NbAreaProp, NbShapesWithName, NbShapesWithColor, | |
416 | NbShapesWithLayer, Doc, PrintStructMode, di); | |
417 | } | |
418 | Standard_Integer NbLabelsShape = 0; | |
586db386 | 419 | di<<"\nStatistis of shapes in the document:\n"; |
7fd59977 | 420 | for(i=0; i<=20; i++) { |
421 | if(HAI->Value(i)==0) break; | |
422 | //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n"; | |
423 | di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n"; | |
424 | NbLabelsShape = NbLabelsShape + HAI->Value(i); | |
425 | } | |
426 | di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n"; | |
427 | di<<"Number of labels with name = "<<NbShapesWithName<<"\n"; | |
428 | di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n"; | |
429 | di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n"; | |
430 | ||
586db386 | 431 | di<<"\nStatistis of Props in the document:\n"; |
7fd59977 | 432 | di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n"; |
433 | di<<"Number of Volume Props = "<<NbVolumeProp<<"\n"; | |
434 | di<<"Number of Area Props = "<<NbAreaProp<<"\n"; | |
435 | ||
436 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
437 | TDF_LabelSequence CLabels; | |
438 | CTool->GetColors(CLabels); | |
586db386 | 439 | di<<"\nNumber of colors = "<<CLabels.Length()<<"\n"; |
7fd59977 | 440 | if(CLabels.Length()>0) { |
441 | for(i=1; i<=CLabels.Length(); i++) { | |
442 | TDF_Label aLabel = CLabels.Value(i); | |
443 | Quantity_Color col; | |
444 | CTool->GetColor(aLabel, col); | |
445 | di<<col.StringName(col.Name())<<" "; | |
446 | } | |
447 | di<<"\n"; | |
448 | } | |
449 | ||
450 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); | |
451 | TDF_LabelSequence LLabels; | |
452 | LTool->GetLayerLabels(LLabels); | |
586db386 | 453 | di<<"\nNumber of layers = "<<LLabels.Length()<<"\n"; |
7fd59977 | 454 | if(LLabels.Length()>0) { |
455 | for(i=1; i<=LLabels.Length(); i++) { | |
456 | TDF_Label aLabel = LLabels.Value(i); | |
457 | TCollection_ExtendedString layerName; | |
458 | LTool->GetLayer(aLabel, layerName); | |
459 | TCollection_AsciiString Entry(layerName,'?'); | |
460 | di<<"\""<<Entry.ToCString() <<"\" "; | |
461 | } | |
462 | di<<"\n"; | |
463 | } | |
464 | ||
465 | di<<"\n"; | |
466 | return 0; | |
467 | } | |
468 | ||
469 | ||
470 | //======================================================================= | |
471 | //function : setPrs | |
472 | //purpose : | |
473 | //======================================================================= | |
474 | static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
475 | { | |
476 | if (argc <2) { | |
586db386 | 477 | di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n"; |
7fd59977 | 478 | return 1; |
479 | } | |
480 | ||
481 | Handle(TDocStd_Document) Doc; | |
482 | DDocStd::GetDocument(argv[1], Doc); | |
586db386 | 483 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 | 484 | |
485 | // collect sequence of labels to set presentation | |
486 | Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); | |
487 | TDF_LabelSequence seq; | |
488 | if ( argc >2 ) { | |
489 | for ( Standard_Integer i=2; i < argc; i++ ) { | |
490 | TDF_Label aLabel; | |
491 | TDF_Tool::Label(Doc->GetData(), argv[i], aLabel); | |
492 | if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) { | |
493 | di << argv[i] << " is not a valid shape label!"; | |
494 | continue; | |
495 | } | |
496 | seq.Append ( aLabel ); | |
497 | } | |
498 | } | |
499 | else { | |
500 | shapes->GetShapes ( seq ); | |
501 | } | |
502 | ||
503 | // set presentations | |
504 | Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
505 | for ( Standard_Integer i=1; i <= seq.Length(); i++ ) { | |
506 | Handle(TPrsStd_AISPresentation) prs; | |
507 | if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) { | |
508 | prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID()); | |
509 | prs->SetMaterial ( Graphic3d_NOM_PLASTIC ); | |
510 | } | |
511 | // Quantity_Color Col; | |
512 | // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) ) | |
513 | // prs->SetColor ( Col.Name() ); | |
514 | // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) ) | |
515 | // prs->SetColor ( Col.Name() ); | |
516 | } | |
517 | return 0; | |
518 | } | |
519 | ||
520 | ||
521 | //======================================================================= | |
522 | //function : show | |
523 | //purpose : | |
524 | //======================================================================= | |
525 | static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
526 | { | |
527 | if (argc <2) { | |
586db386 | 528 | di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n"; |
7fd59977 | 529 | return 1; |
530 | } | |
531 | ||
0e93d9e5 | 532 | Handle(TDocStd_Document) aDoc; |
533 | DDocStd::GetDocument (argv[1], aDoc); | |
534 | if (aDoc.IsNull()) | |
535 | { | |
536 | std::cout << argv[1] << " is not a document\n"; | |
537 | return 1; | |
538 | } | |
7fd59977 | 539 | |
540 | // init viewer | |
0e93d9e5 | 541 | TDF_Label aRoot = aDoc->GetData()->Root(); |
542 | Handle(TPrsStd_AISViewer) aDocViewer; | |
543 | TCollection_AsciiString aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1"; | |
544 | if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer)) | |
545 | { | |
546 | ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), ""); | |
547 | aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext()); | |
548 | } | |
7fd59977 | 549 | |
7fd59977 | 550 | // collect sequence of labels to display |
0e93d9e5 | 551 | Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main()); |
7fd59977 | 552 | TDF_LabelSequence seq; |
553 | if ( argc >2 ) { | |
554 | for ( Standard_Integer i=2; i < argc; i++ ) { | |
555 | TDF_Label aLabel; | |
0e93d9e5 | 556 | TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel); |
7fd59977 | 557 | if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) { |
558 | di << argv[i] << " is not a valid shape label!"; | |
559 | continue; | |
560 | } | |
561 | seq.Append ( aLabel ); | |
562 | } | |
563 | } | |
564 | else { | |
565 | shapes->GetFreeShapes ( seq ); | |
566 | } | |
567 | ||
568 | // set presentations and show | |
569 | //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
570 | for ( Standard_Integer i=1; i <= seq.Length(); i++ ) { | |
571 | Handle(TPrsStd_AISPresentation) prs; | |
572 | if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) { | |
573 | prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID()); | |
574 | prs->SetMaterial ( Graphic3d_NOM_PLASTIC ); | |
575 | } | |
576 | // Quantity_Color Col; | |
577 | // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) ) | |
578 | // prs->SetColor ( Col.Name() ); | |
579 | // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) ) | |
580 | // prs->SetColor ( Col.Name() ); | |
581 | prs->Display(Standard_True); | |
582 | } | |
0e93d9e5 | 583 | TPrsStd_AISViewer::Update (aDoc->GetData()->Root()); |
7fd59977 | 584 | return 0; |
585 | } | |
586 | ||
ab1f4580 | 587 | //! XDisplay command implementation. |
588 | class XDEDRAW_XDisplayTool | |
589 | { | |
590 | public: | |
591 | //! XDisplay command interface. | |
592 | static Standard_Integer XDisplay (Draw_Interpretor& theDI, | |
593 | Standard_Integer theNbArgs, | |
594 | const char** theArgVec) | |
595 | { | |
596 | XDEDRAW_XDisplayTool aTool; | |
597 | return aTool.xdisplay (theDI, theNbArgs, theArgVec); | |
598 | } | |
599 | ||
600 | private: | |
601 | //! Constructor. | |
602 | XDEDRAW_XDisplayTool() | |
603 | : myDispMode(-2), | |
604 | myHiMode (-2), | |
605 | myToPrefixDocName (Standard_True), | |
606 | myToGetNames (Standard_True), | |
607 | myToExplore (Standard_False) {} | |
608 | ||
609 | //! Display single label. | |
610 | Standard_Integer displayLabel (Draw_Interpretor& theDI, | |
611 | const TDF_Label& theLabel, | |
612 | const TCollection_AsciiString& theNamePrefix, | |
613 | const TopLoc_Location& theLoc) | |
614 | { | |
615 | TCollection_AsciiString aName; | |
616 | if (myToGetNames) | |
617 | { | |
618 | Handle(TDataStd_Name) aNodeName; | |
619 | if (theLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName)) | |
620 | { | |
621 | aName = aNodeName->Get(); | |
622 | } | |
623 | if (aName.IsEmpty()) | |
624 | { | |
625 | TDF_Label aRefLabel; | |
626 | if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel) | |
627 | && aRefLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName)) | |
628 | { | |
629 | aName = aNodeName->Get(); | |
630 | } | |
631 | } | |
632 | ||
633 | if (aName.IsEmpty()) | |
634 | { | |
635 | TDF_Tool::Entry (theLabel, aName); | |
636 | } | |
637 | for (Standard_Integer aNameIndex = 1;; ++aNameIndex) | |
638 | { | |
639 | if (myNameMap.Add (aName)) | |
640 | { | |
641 | break; | |
642 | } | |
643 | aName = aNodeName->Get() + "_" + aNameIndex; | |
644 | } | |
645 | } | |
646 | else | |
647 | { | |
648 | TDF_Tool::Entry (theLabel, aName); | |
649 | } | |
650 | aName = theNamePrefix + aName; | |
651 | ||
652 | if (myToExplore) | |
653 | { | |
654 | TDF_Label aRefLabel = theLabel; | |
655 | XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel); | |
656 | if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel)) | |
657 | { | |
658 | aName += "/"; | |
659 | const TopLoc_Location aLoc = theLoc * XCAFDoc_ShapeTool::GetLocation (theLabel); | |
660 | for (TDF_ChildIterator aChildIter (aRefLabel); aChildIter.More(); aChildIter.Next()) | |
661 | { | |
662 | if (displayLabel (theDI, aChildIter.Value(), aName, aLoc) == 1) | |
663 | { | |
664 | return 1; | |
665 | } | |
666 | } | |
667 | return 0; | |
668 | } | |
669 | } | |
670 | ||
671 | Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject (theLabel); | |
672 | if (!theLoc.IsIdentity()) | |
673 | { | |
674 | aPrs->SetLocalTransformation (theLoc); | |
675 | } | |
676 | if (myDispMode != -2) | |
677 | { | |
678 | if (myDispMode == -1) | |
679 | { | |
680 | aPrs->UnsetDisplayMode(); | |
681 | } | |
682 | if (!aPrs->AcceptDisplayMode (myDispMode)) | |
683 | { | |
684 | std::cout << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myDispMode << " display mode\n"; | |
685 | return 1; | |
686 | } | |
687 | else | |
688 | { | |
689 | aPrs->SetDisplayMode (myDispMode); | |
690 | } | |
691 | } | |
692 | if (myHiMode != -2) | |
693 | { | |
694 | if (myHiMode != -1 | |
695 | && !aPrs->AcceptDisplayMode (myHiMode)) | |
696 | { | |
697 | std::cout << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myHiMode << " display mode\n"; | |
698 | return 1; | |
699 | } | |
700 | aPrs->SetHilightMode (myHiMode); | |
701 | } | |
702 | ||
703 | ViewerTest::Display (aName, aPrs, false); | |
704 | theDI << aName << " "; | |
705 | return 0; | |
706 | } | |
707 | ||
708 | //! XDisplay command implementation. | |
709 | Standard_Integer xdisplay (Draw_Interpretor& theDI, | |
710 | Standard_Integer theNbArgs, | |
711 | const char** theArgVec) | |
712 | { | |
713 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
714 | if (aContext.IsNull()) | |
715 | { | |
716 | std::cout << "Error: no active view!\n"; | |
717 | return 1; | |
718 | } | |
719 | ||
720 | ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView()); | |
721 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
722 | { | |
723 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); | |
724 | anArgCase.LowerCase(); | |
725 | if (anAutoUpdater.parseRedrawMode (anArgCase)) | |
726 | { | |
727 | continue; | |
728 | } | |
729 | else if (anArgIter + 1 < theNbArgs | |
730 | && myDispMode == -2 | |
731 | && (anArgCase == "-dispmode" | |
732 | || anArgCase == "-displaymode") | |
733 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue()) | |
734 | { | |
735 | myDispMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue(); | |
736 | } | |
737 | else if (anArgIter + 1 < theNbArgs | |
738 | && myHiMode == -2 | |
739 | && (anArgCase == "-himode" | |
740 | || anArgCase == "-highmode" | |
741 | || anArgCase == "-highlightmode") | |
742 | && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue()) | |
743 | { | |
744 | myHiMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue(); | |
745 | } | |
746 | else if (anArgCase == "-docprefix" | |
747 | || anArgCase == "-nodocprefix") | |
748 | { | |
749 | myToPrefixDocName = Standard_True; | |
750 | if (anArgIter + 1 < theNbArgs | |
751 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToPrefixDocName)) | |
752 | { | |
753 | ++anArgIter; | |
754 | } | |
755 | if (anArgCase.StartsWith ("-no")) | |
756 | { | |
757 | myToPrefixDocName = !myToPrefixDocName; | |
758 | } | |
759 | } | |
760 | else if (anArgCase == "-names" | |
761 | || anArgCase == "-nonames") | |
762 | { | |
763 | myToGetNames = Standard_True; | |
764 | if (anArgIter + 1 < theNbArgs | |
765 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToGetNames)) | |
766 | { | |
767 | ++anArgIter; | |
768 | } | |
769 | if (anArgCase.StartsWith ("-no")) | |
770 | { | |
771 | myToGetNames = !myToGetNames; | |
772 | } | |
773 | } | |
774 | else if (anArgCase == "-explore" | |
775 | || anArgCase == "-noexplore") | |
776 | { | |
777 | myToExplore = Standard_True; | |
778 | if (anArgIter + 1 < theNbArgs | |
779 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToExplore)) | |
780 | { | |
781 | ++anArgIter; | |
782 | } | |
783 | if (anArgCase.StartsWith ("-no")) | |
784 | { | |
785 | myToExplore = !myToExplore; | |
786 | } | |
787 | } | |
788 | else | |
789 | { | |
790 | if (myDoc.IsNull() | |
791 | && DDocStd::GetDocument (theArgVec[anArgIter], myDoc, Standard_False)) | |
792 | { | |
793 | myDocName = theArgVec[anArgIter]; | |
794 | continue; | |
795 | } | |
796 | ||
797 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
798 | const Standard_Integer aFirstSplit = aValue.Search (":"); | |
799 | if (!IsDigit (aValue.Value (1)) | |
800 | && aFirstSplit >= 2 | |
801 | && aFirstSplit < aValue.Length()) | |
802 | { | |
803 | TCollection_AsciiString aDocName = aValue.SubString (1, aFirstSplit - 1); | |
804 | Standard_CString aDocNameStr = aDocName.ToCString(); | |
805 | Handle(TDocStd_Document) aDoc; | |
806 | if (DDocStd::GetDocument (aDocNameStr, aDoc, Standard_False)) | |
807 | { | |
808 | aValue = aValue.SubString (aFirstSplit + 1, aValue.Length()); | |
809 | if (!myDoc.IsNull() | |
810 | && myDoc != aDoc) | |
811 | { | |
812 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
813 | return 1; | |
814 | } | |
815 | myDoc = aDoc; | |
816 | myDocName = aDocName; | |
817 | } | |
818 | } | |
819 | if (myDoc.IsNull()) | |
820 | { | |
821 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
822 | return 1; | |
823 | } | |
824 | ||
825 | TDF_Label aLabel; | |
826 | TDF_Tool::Label (myDoc->GetData(), aValue.ToCString(), aLabel); | |
827 | if (aLabel.IsNull() | |
828 | || !XCAFDoc_ShapeTool::IsShape (aLabel)) | |
829 | { | |
830 | std::cout << "Syntax error: " << aValue << " is not a valid shape label\n"; | |
831 | return 1; | |
832 | } | |
833 | myLabels.Append (aLabel); | |
834 | } | |
835 | } | |
836 | if (myDoc.IsNull()) | |
837 | { | |
838 | std::cout << "Syntax error: not enough arguments\n"; | |
839 | return 1; | |
840 | } | |
841 | if (myLabels.IsEmpty()) | |
842 | { | |
843 | XCAFDoc_DocumentTool::ShapeTool (myDoc->Main())->GetFreeShapes (myLabels); | |
844 | } | |
845 | ||
846 | for (TDF_LabelSequence::Iterator aLabIter (myLabels); aLabIter.More(); aLabIter.Next()) | |
847 | { | |
848 | const TDF_Label& aLabel = aLabIter.Value(); | |
849 | if (displayLabel (theDI, aLabel, myToPrefixDocName ? myDocName + ":" : "", TopLoc_Location()) == 1) | |
850 | { | |
851 | return 1; | |
852 | } | |
853 | } | |
854 | return 0; | |
855 | } | |
856 | ||
857 | private: | |
858 | NCollection_Map<TCollection_AsciiString, TCollection_AsciiString> | |
859 | myNameMap; //!< names map to handle collisions | |
860 | Handle(TDocStd_Document) myDoc; //!< document | |
861 | TCollection_AsciiString myDocName; //!< document name | |
862 | TDF_LabelSequence myLabels; //!< labels to display | |
863 | Standard_Integer myDispMode; //!< shape display mode | |
864 | Standard_Integer myHiMode; //!< shape highlight mode | |
865 | Standard_Boolean myToPrefixDocName; //!< flag to prefix objects with document name | |
866 | Standard_Boolean myToGetNames; //!< flag to use label names or tags | |
867 | Standard_Boolean myToExplore; //!< flag to explore assembles | |
868 | }; | |
7fd59977 | 869 | |
870 | //======================================================================= | |
871 | //function : xwd | |
872 | //purpose : | |
873 | //======================================================================= | |
874 | static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
875 | { | |
876 | if (argc <3) { | |
586db386 | 877 | di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n"; |
7fd59977 | 878 | return 1; |
879 | } | |
880 | ||
881 | Handle(TDocStd_Document) Doc; | |
882 | DDocStd::GetDocument(argv[1], Doc); | |
586db386 | 883 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 | 884 | |
885 | Handle(AIS_InteractiveContext) IC; | |
886 | if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) { | |
887 | di << "Cannot find viewer for document " << argv[1] << "\n"; | |
888 | return 1; | |
889 | } | |
890 | ||
6a24c6de | 891 | Handle(V3d_Viewer) aViewer = IC->CurrentViewer(); |
892 | V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator(); | |
893 | if (aViewIter.More()) | |
894 | { | |
895 | aViewIter.Value()->Dump ( argv[2] ); | |
7fd59977 | 896 | } |
897 | else { | |
898 | di << "Cannot find an active view in a viewer " << argv[1] << "\n"; | |
899 | return 1; | |
900 | } | |
901 | ||
902 | return 0; | |
903 | } | |
904 | ||
905 | ||
906 | //======================================================================= | |
907 | //function : XAttributeValue | |
908 | //purpose : | |
909 | //======================================================================= | |
910 | static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
911 | { | |
1c8fc6be | 912 | if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; } |
913 | Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1])); | |
914 | if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; } | |
7fd59977 | 915 | |
916 | TDF_Label lab; | |
917 | TDF_Tool::Label(browser->Data(),argv[2],lab); | |
1c8fc6be | 918 | if ( lab.IsNull() ) { std::cout << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; } |
7fd59977 | 919 | |
91322f44 | 920 | Standard_Integer num = Draw::Atoi ( argv[3] ); |
7fd59977 | 921 | TDF_AttributeIterator itr(lab,Standard_False); |
922 | for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next(); | |
923 | ||
1c8fc6be | 924 | if ( ! itr.More() ) { std::cout << "Syntax error: Attribute #" << num << " not found\n"; return 1; } |
7fd59977 | 925 | |
926 | const Handle(TDF_Attribute)& att = itr.Value(); | |
927 | if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) { | |
f767df4e | 928 | Standard_CString type = ""; |
7fd59977 | 929 | if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link"; |
930 | else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link"; | |
931 | else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link"; | |
932 | else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link"; | |
933 | else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link"; | |
934 | else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link"; | |
935 | else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link"; | |
7fd59977 | 936 | Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att); |
937 | TCollection_AsciiString ref; | |
938 | if ( TN->HasFather() ) { | |
939 | TDF_Tool::Entry ( TN->Father()->Label(), ref ); | |
940 | di << type << " ==> " << ref.ToCString(); | |
941 | } | |
942 | else { | |
943 | di << type << " <== (" << ref.ToCString(); | |
944 | Handle(TDataStd_TreeNode) child = TN->First(); | |
945 | while ( ! child.IsNull() ) { | |
f767df4e | 946 | TDF_Tool::Entry ( child->Label(), ref ); |
947 | if ( child != TN->First() ) di << ", "; | |
948 | di << ref.ToCString(); | |
949 | child = child->Next(); | |
7fd59977 | 950 | } |
951 | di << ")"; | |
952 | } | |
953 | } | |
f767df4e | 954 | else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) { |
955 | Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att ); | |
956 | TCollection_AsciiString ref; | |
957 | TDF_Tool::Entry ( val->Get(), ref ); | |
958 | di << "==> " << ref.ToCString(); | |
959 | } | |
7fd59977 | 960 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) { |
961 | Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att ); | |
962 | TCollection_AsciiString str ( val->Get() ); | |
963 | di << str.ToCString(); | |
964 | } | |
965 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) { | |
966 | Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att ); | |
967 | TCollection_AsciiString str ( val->Get() ); | |
968 | di << str.ToCString(); | |
969 | } | |
f767df4e | 970 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) { |
971 | Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att ); | |
972 | TCollection_AsciiString str ( val->Get(), '?' ); | |
7fd59977 | 973 | di << str.ToCString(); |
974 | } | |
f767df4e | 975 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) { |
976 | Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att ); | |
977 | TCollection_AsciiString str ( val->Get(), '?' ); | |
7fd59977 | 978 | di << str.ToCString(); |
979 | } | |
f767df4e | 980 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) { |
981 | Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att ); | |
7fd59977 | 982 | TCollection_AsciiString str ( val->Get(), '?' ); |
983 | di << str.ToCString(); | |
984 | } | |
f767df4e | 985 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) { |
986 | Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att ); | |
987 | for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) { | |
988 | if ( j > val->Lower() ) di << ", "; | |
989 | TCollection_AsciiString str ( val->Value(j) ); | |
990 | di << str.ToCString(); | |
991 | } | |
992 | } | |
7fd59977 | 993 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) { |
994 | Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att ); | |
995 | for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) { | |
996 | if ( j > val->Lower() ) di << ", "; | |
997 | TCollection_AsciiString str ( val->Value(j) ); | |
998 | di << str.ToCString(); | |
999 | } | |
1000 | } | |
f767df4e | 1001 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) { |
1002 | Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att ); | |
1003 | for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) { | |
1004 | if ( j > val->Lower() ) di << ", "; | |
1005 | TCollection_AsciiString str ( val->Value(j) ); | |
1006 | di << str.ToCString(); | |
1007 | } | |
1008 | } | |
7fd59977 | 1009 | else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) { |
1010 | Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att ); | |
1011 | TopoDS_Shape S = val->Get(); | |
1012 | di << S.TShape()->DynamicType()->Name(); | |
1013 | if ( ! S.Location().IsIdentity() ) di << "(located)"; | |
1014 | } | |
f767df4e | 1015 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) { |
1016 | Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att ); | |
1017 | TCollection_AsciiString str ( val->Get() ); | |
1018 | di << str.ToCString(); | |
1019 | } | |
1020 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) { | |
1021 | Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att ); | |
1022 | TCollection_AsciiString str ( val->Get() ); | |
1023 | di << str.ToCString(); | |
1024 | } | |
1025 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) { | |
1026 | Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att ); | |
1027 | gp_Pnt myCentroid = val->Get(); | |
1028 | di << "(" ; | |
1029 | di << myCentroid.X(); | |
1030 | di <<" , "; | |
1031 | di << myCentroid.Y(); | |
1032 | di <<" , "; | |
1033 | di << myCentroid.Z(); | |
1034 | di << ")"; | |
1035 | } | |
7fd59977 | 1036 | else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) { |
1037 | if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly"; | |
1038 | if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible"; | |
1039 | } | |
1040 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) { | |
1041 | Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att ); | |
973d410e | 1042 | Quantity_ColorRGBA C = val->GetColorRGBA(); |
7fd59977 | 1043 | char string[260]; |
973d410e | 1044 | Sprintf ( string, "%s (%g, %g, %g, %g)", C.GetRGB().StringName ( C.GetRGB().Name() ), |
1045 | C.GetRGB().Red(), C.GetRGB().Green(), C.GetRGB().Blue(), C.Alpha()); | |
7fd59977 | 1046 | di << string; |
1047 | } | |
1048 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) { | |
1049 | Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att ); | |
1050 | Standard_Integer kind = val->GetKind(); | |
1051 | Handle(TColStd_HArray1OfReal) HAR = val->GetVal(); | |
1052 | if(kind<20) { //dimension | |
1053 | di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])"; | |
1054 | } | |
1055 | else { | |
1056 | switch(kind) { | |
1057 | case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break; | |
1058 | case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break; | |
1059 | case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break; | |
1060 | case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1061 | case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1062 | case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1063 | case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1064 | case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1065 | case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1066 | case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1067 | case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1068 | case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break; | |
1069 | case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break; | |
1070 | case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break; | |
1071 | case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1072 | case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1073 | case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1074 | case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1075 | case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1076 | case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1077 | case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break; | |
1078 | } | |
1079 | } | |
1080 | } | |
1081 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) { | |
1082 | Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att ); | |
1083 | Standard_Real dens = val->GetDensity(); | |
1084 | Standard_CString dimdens = "g/cu sm"; | |
1085 | if(dens==0) | |
1086 | di<<val->GetName()->ToCString(); | |
1087 | else | |
1088 | di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")"; | |
1089 | } | |
1090 | else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) { | |
1091 | Standard_CString type; | |
1092 | if ( att->ID() == XCAFDoc::LayerRefGUID() ) { | |
1093 | type = "Layer Instance Link"; | |
1094 | } | |
1095 | else if ( att->ID() == XCAFDoc::SHUORefGUID() ) { | |
1096 | type = "SHUO Instance Link"; | |
1097 | } | |
1098 | else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) { | |
1099 | type = "DatumToler Link"; | |
1100 | } | |
1c9d3225 | 1101 | else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) { |
1102 | type = "Dimension Link First"; | |
1103 | } | |
1104 | else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) { | |
1105 | type = "Dimension Link Second"; | |
1106 | } | |
1107 | else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){ | |
1108 | type = "GeomTolerance Link"; | |
9ebaae37 | 1109 | } |
400af1bc | 1110 | else if ( att->ID() == XCAFDoc::DatumRefGUID() ){ |
1111 | type = "Datum Link"; | |
1112 | } | |
2df785d7 | 1113 | else if (att->ID() == XCAFDoc::ViewRefShapeGUID()){ |
1114 | type = "View Shape Link"; | |
1115 | } | |
1116 | else if (att->ID() == XCAFDoc::ViewRefGDTGUID()){ | |
1117 | type = "View GD&T Link"; | |
1118 | } | |
0c63f2f8 | 1119 | else if (att->ID() == XCAFDoc::ViewRefPlaneGUID()) { |
1120 | type = "View Clipping Plane Link"; | |
1121 | } | |
7fd59977 | 1122 | else return 0; |
1123 | ||
1124 | Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att); | |
1125 | TCollection_AsciiString ref; | |
1126 | Standard_Integer ii = 1; | |
1127 | if (DETGN->NbFathers()!=0) { | |
1128 | ||
1129 | TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref ); | |
1130 | di << type<< " ==> (" << ref.ToCString(); | |
1131 | for (ii = 2; ii <= DETGN->NbFathers(); ii++) { | |
1132 | TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref ); | |
1133 | di << ", " << ref.ToCString(); | |
1134 | } | |
1135 | di << ") "; | |
1136 | } | |
1137 | ii = 1; | |
1138 | if (DETGN->NbChildren()!=0) { | |
1139 | TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref ); | |
1140 | di << type<< " <== (" << ref.ToCString(); | |
1141 | for (ii = 2; ii <= DETGN->NbChildren(); ii++) { | |
1142 | TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref ); | |
1143 | di << ", " << ref.ToCString(); | |
1144 | } | |
1145 | di << ")"; | |
1146 | } | |
1147 | } | |
1148 | return 0; | |
1149 | } | |
1150 | ||
1151 | ||
1152 | //======================================================================= | |
1153 | //function : setviewName | |
1154 | //purpose : | |
1155 | //======================================================================= | |
1156 | static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1157 | { | |
1158 | if (argc <2) { | |
586db386 | 1159 | di<<"Use: "<<argv[0]<<" (1/0)\n"; |
7fd59977 | 1160 | return 1; |
1161 | } | |
1162 | Standard_Boolean mode = Standard_False; | |
91322f44 | 1163 | if (Draw::Atoi(argv[1]) == 1) mode = Standard_True; |
7fd59977 | 1164 | XCAFPrs::SetViewNameMode(mode); |
1165 | return 0; | |
1166 | } | |
1167 | ||
1168 | ||
1169 | //======================================================================= | |
1170 | //function : getviewName | |
1171 | //purpose : auxilary | |
1172 | //======================================================================= | |
1173 | ||
1174 | static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) | |
1175 | { | |
586db386 | 1176 | if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n"; |
1177 | else di << "Display names OFF\n"; | |
7fd59977 | 1178 | return 0; |
1179 | } | |
1180 | ||
1181 | ||
5cbef0fe S |
1182 | //======================================================================= |
1183 | //function : XSetTransparency | |
1184 | //purpose : | |
1185 | //======================================================================= | |
1186 | static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1187 | { | |
1188 | if (argc < 3) { | |
586db386 | 1189 | di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n"; |
5cbef0fe S |
1190 | return 1; |
1191 | } | |
1192 | ||
1193 | Handle(TDocStd_Document) Doc; | |
1194 | DDocStd::GetDocument(argv[1], Doc); | |
586db386 | 1195 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
5cbef0fe | 1196 | |
91322f44 | 1197 | const Standard_Real aTransparency = Draw::Atof(argv[2]); |
5cbef0fe S |
1198 | |
1199 | // collect sequence of labels | |
1200 | Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); | |
1201 | TDF_LabelSequence seq; | |
1202 | if ( argc > 3 ) { | |
1203 | for ( Standard_Integer i=3; i < argc; i++ ) { | |
1204 | TDF_Label aLabel; | |
1205 | TDF_Tool::Label(Doc->GetData(), argv[i], aLabel); | |
1206 | if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) { | |
1207 | di << argv[i] << " is not a valid shape label!"; | |
1208 | continue; | |
1209 | } | |
1210 | seq.Append ( aLabel ); | |
1211 | } | |
1212 | } | |
1213 | else { | |
1214 | shapes->GetFreeShapes ( seq ); | |
1215 | } | |
1216 | ||
1217 | // find presentations and set transparency | |
1218 | for ( Standard_Integer i=1; i <= seq.Length(); i++ ) { | |
1219 | Handle(TPrsStd_AISPresentation) prs; | |
1220 | if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) { | |
1221 | prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID()); | |
1222 | prs->SetMaterial ( Graphic3d_NOM_PLASTIC ); | |
1223 | } | |
1224 | prs->SetTransparency( aTransparency ); | |
1225 | } | |
1226 | TPrsStd_AISViewer::Update(Doc->GetData()->Root()); | |
1227 | return 0; | |
1228 | } | |
1229 | ||
a2d5ab2e | 1230 | //======================================================================= |
1231 | //function : XShowFaceBoundary | |
1232 | //purpose : Set face boundaries on/off | |
1233 | //======================================================================= | |
1234 | static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di, | |
1235 | Standard_Integer argc, | |
1236 | const char ** argv) | |
1237 | { | |
1238 | if (( argc != 4 && argc < 7 ) || argc > 9) | |
1239 | { | |
1240 | di << "Usage :\n " << argv[0] | |
1241 | << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n" | |
1242 | << " Doc - is the document name. \n" | |
1243 | << " Label - is the shape label. \n" | |
1244 | << " IsOn - flag indicating whether the boundaries\n" | |
1245 | << " should be turned on or off (can be set\n" | |
1246 | << " to 0 (off) or 1 (on)).\n" | |
1247 | << " R, G, B - red, green and blue components of boundary\n" | |
1248 | << " color in range (0 - 255).\n" | |
1249 | << " (default is (0, 0, 0)\n" | |
1250 | << " LineWidth - line width\n" | |
1251 | << " (default is 1)\n" | |
1252 | << " LineStyle - line fill style :\n" | |
1253 | << " 0 - solid \n" | |
1254 | << " 1 - dashed \n" | |
1255 | << " 2 - dot \n" | |
1256 | << " 3 - dashdot\n" | |
1257 | << " (default is solid)"; | |
1258 | ||
1259 | return 1; | |
1260 | } | |
1261 | ||
1262 | // get specified document | |
1263 | Handle(TDocStd_Document) aDoc; | |
1264 | DDocStd::GetDocument (argv[1], aDoc); | |
1265 | if (aDoc.IsNull()) | |
1266 | { | |
586db386 | 1267 | di << argv[1] << " is not a document\n"; |
a2d5ab2e | 1268 | return 1; |
1269 | } | |
1270 | ||
1271 | Handle(AIS_InteractiveContext) aContext; | |
1272 | if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext)) | |
1273 | { | |
1274 | di << "Cannot find viewer for document " << argv[1] << "\n"; | |
1275 | return 1; | |
1276 | } | |
1277 | ||
1278 | // get shape tool for shape verification | |
1279 | Handle(XCAFDoc_ShapeTool) aShapes = | |
1280 | XCAFDoc_DocumentTool::ShapeTool (aDoc->Main()); | |
1281 | ||
1282 | // get label and validate that it is a shape label | |
1283 | TDF_Label aLabel; | |
1284 | TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel); | |
1285 | if (aLabel.IsNull() || !aShapes->IsShape (aLabel)) | |
1286 | { | |
1287 | di << argv[2] << " is not a valid shape label!"; | |
1288 | return 1; | |
1289 | } | |
1290 | ||
1291 | // get presentation from label | |
1292 | Handle(TPrsStd_AISPresentation) aPrs; | |
1293 | if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs)) | |
1294 | { | |
1295 | aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ()); | |
1296 | } | |
1297 | ||
1298 | Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS (); | |
1299 | if (anInteractive.IsNull ()) | |
1300 | { | |
1301 | di << "Can't set drawer attributes.\n" | |
1302 | "Interactive object for shape label doesn't exists."; | |
1303 | return 1; | |
1304 | } | |
1305 | ||
1306 | // get drawer | |
6262338c | 1307 | const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes (); |
a2d5ab2e | 1308 | |
1309 | // default attributes | |
ee2be2a8 | 1310 | Standard_Real aRed = 0.0; |
1311 | Standard_Real aGreen = 0.0; | |
1312 | Standard_Real aBlue = 0.0; | |
1313 | Standard_Real aWidth = 1.0; | |
1314 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
a2d5ab2e | 1315 | |
1316 | // turn boundaries on/off | |
91322f44 | 1317 | Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1); |
a2d5ab2e | 1318 | aDrawer->SetFaceBoundaryDraw (isBoundaryDraw); |
1319 | ||
1320 | // set boundary color | |
1321 | if (argc >= 7) | |
1322 | { | |
1323 | // Text color | |
91322f44 | 1324 | aRed = Draw::Atof (argv[4])/255.; |
1325 | aGreen = Draw::Atof (argv[5])/255.; | |
1326 | aBlue = Draw::Atof (argv[6])/255.; | |
a2d5ab2e | 1327 | } |
1328 | ||
1329 | // set line width | |
1330 | if (argc >= 8) | |
1331 | { | |
91322f44 | 1332 | aWidth = (Standard_Real)Draw::Atof (argv[7]); |
a2d5ab2e | 1333 | } |
1334 | ||
1335 | // select appropriate line type | |
1336 | if (argc == 9) | |
1337 | { | |
3a4a3962 | 1338 | if (!ViewerTest::ParseLineType (argv[8], aLineType)) |
a2d5ab2e | 1339 | { |
3a4a3962 | 1340 | std::cout << "Syntax error: unknown line type '" << argv[8] << "'\n"; |
a2d5ab2e | 1341 | } |
1342 | } | |
1343 | ||
1344 | Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB); | |
1345 | ||
1346 | Handle(Prs3d_LineAspect) aBoundaryAspect = | |
1347 | new Prs3d_LineAspect (aColor, aLineType, aWidth); | |
1348 | ||
1349 | aDrawer->SetFaceBoundaryAspect (aBoundaryAspect); | |
1350 | ||
0577ae8c | 1351 | aContext->Redisplay (anInteractive, Standard_True); |
a2d5ab2e | 1352 | |
1353 | return 0; | |
1354 | } | |
5cbef0fe | 1355 | |
da0e82aa | 1356 | //======================================================================= |
1357 | //function : testDoc | |
1358 | //purpose : Method to test destruction of document | |
1359 | //======================================================================= | |
498ce76b | 1360 | static Standard_Integer testDoc (Draw_Interpretor&, |
da0e82aa | 1361 | Standard_Integer argc, |
1362 | const char ** argv) | |
1363 | { | |
1364 | if( argc < 2 ) | |
1365 | { | |
04232180 | 1366 | std::cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<std::endl; |
da0e82aa | 1367 | return 1; |
1368 | } | |
1369 | TopoDS_Shape shape = DBRep::Get(argv[1]); | |
1370 | if( shape.IsNull()) | |
1371 | return 1; | |
1372 | ||
6fe96f84 | 1373 | Handle(TDocStd_Application) anApp = DDocStd::GetApplication(); |
da0e82aa | 1374 | |
fff263bd | 1375 | Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF"); |
6fe96f84 | 1376 | aD1->Open(anApp); |
da0e82aa | 1377 | |
0e93d9e5 | 1378 | TCollection_AsciiString aViewName ("Driver1/DummyDocument/View1"); |
1379 | ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), ""); | |
1380 | TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext()); | |
1381 | ||
da0e82aa | 1382 | // get shape tool for shape verification |
1383 | Handle(XCAFDoc_ShapeTool) aShapes = | |
1384 | XCAFDoc_DocumentTool::ShapeTool (aD1->Main()); | |
1385 | TDF_Label aLab = aShapes->AddShape(shape); | |
1386 | ||
1387 | Handle(Geom_Axis2Placement) aPlacement = | |
1388 | new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX()); | |
1389 | Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement); | |
1390 | ||
1391 | Handle(TNaming_NamedShape) NS; | |
1392 | Handle(TPrsStd_AISPresentation) prs; | |
1393 | if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) { | |
1394 | prs = TPrsStd_AISPresentation::Set( NS ); | |
1395 | } | |
1396 | ||
1397 | if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) ) | |
1398 | prs->Display(); | |
da0e82aa | 1399 | |
1400 | TPrsStd_AISViewer::Update(aLab); | |
0e93d9e5 | 1401 | ViewerTest::GetAISContext()->Display (aTriShape, Standard_True); |
d01cc61d | 1402 | aD1->BeforeClose(); |
da0e82aa | 1403 | aD1->Close(); |
0e93d9e5 | 1404 | ViewerTest::RemoveView (aViewName); |
da0e82aa | 1405 | return 0; |
1406 | } | |
1407 | ||
1408 | ||
7fd59977 | 1409 | //======================================================================= |
1410 | //function : Init | |
1411 | //purpose : | |
1412 | //======================================================================= | |
1413 | ||
1414 | void XDEDRAW::Init(Draw_Interpretor& di) | |
1415 | { | |
7fd59977 | 1416 | static Standard_Boolean initactor = Standard_False; |
c48e2889 | 1417 | if (initactor) |
1418 | { | |
1419 | return; | |
1420 | } | |
1421 | initactor = Standard_True; | |
7fd59977 | 1422 | |
02a0b964 | 1423 | // Load static variables for STEPCAF (ssv; 16.08.2012) |
1424 | STEPCAFControl_Controller::Init(); | |
1425 | ||
6fe96f84 | 1426 | // Initialize XCAF formats |
1427 | Handle(TDocStd_Application) anApp = DDocStd::GetApplication(); | |
1428 | BinXCAFDrivers::DefineFormat(anApp); | |
1429 | XmlXCAFDrivers::DefineFormat(anApp); | |
7fd59977 | 1430 | |
6fe96f84 | 1431 | // Register driver in global table for displaying XDE documents |
1432 | // in 3d viewer using OCAF mechanics | |
1433 | TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver); | |
7fd59977 | 1434 | |
1435 | //===================================== | |
1436 | // General commands | |
1437 | //===================================== | |
1438 | ||
1439 | Standard_CString g = "XDE general commands"; | |
1440 | ||
1441 | di.Add ("XNewDoc","DocName \t: Create new DECAF document", | |
1442 | __FILE__, newDoc, g); | |
1443 | ||
1444 | di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session", | |
1445 | __FILE__, saveDoc, g); | |
1446 | ||
02a0b964 | 1447 | di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path", |
1448 | __FILE__, openDoc, g); | |
1449 | ||
7fd59977 | 1450 | di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure", |
1451 | __FILE__, dump, g); | |
1452 | ||
1453 | di.Add ("XStat","Doc \t: Print statistics of document", | |
1454 | __FILE__, statdoc, g); | |
1455 | ||
1456 | di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc", | |
1457 | __FILE__, setPrs, g); | |
1458 | ||
1459 | di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window", | |
1460 | __FILE__, show, g); | |
1461 | ||
ab1f4580 | 1462 | di.Add ("XDisplay", |
1463 | "XDisplay Doc [label1 [label2 [...]]] [-explore {on|off}] [-docPrefix {on|off}] [-names {on|off}]" | |
1464 | "\n\t\t: [-noupdate] [-dispMode Mode] [-highMode Mode]" | |
1465 | "\n\t\t: Displays document (parts) in 3D Viewer." | |
1466 | "\n\t\t: -dispMode Presentation display mode." | |
1467 | "\n\t\t: -highMode Presentation highlight mode." | |
1468 | "\n\t\t: -docPrefix Prepend document name to object names; TRUE by default." | |
1469 | "\n\t\t: -names Use object names instead of label tag; TRUE by default." | |
1470 | "\n\t\t: -explore Explode labels to leaves; FALSE by default.", | |
1471 | __FILE__, XDEDRAW_XDisplayTool::XDisplay, g); | |
1472 | ||
7fd59977 | 1473 | di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file", |
1474 | __FILE__, xwd, g); | |
1475 | ||
1476 | di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser", | |
1477 | __FILE__, XAttributeValue, g); | |
1478 | ||
1479 | di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.", | |
1480 | __FILE__, setviewName, g); | |
1481 | ||
1482 | di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.", | |
1483 | __FILE__, getviewName, g); | |
1484 | ||
5cbef0fe S |
1485 | di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc", |
1486 | __FILE__, XSetTransparency, g); | |
1487 | ||
a2d5ab2e | 1488 | di.Add ("XShowFaceBoundary", |
1489 | "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:" | |
1490 | "- turns on/off drawing of face boundaries and defines boundary line style", | |
1491 | __FILE__, XShowFaceBoundary, g); | |
da0e82aa | 1492 | di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g); |
a2d5ab2e | 1493 | |
7fd59977 | 1494 | // Specialized commands |
1495 | XDEDRAW_Shapes::InitCommands ( di ); | |
1496 | XDEDRAW_Colors::InitCommands ( di ); | |
1497 | XDEDRAW_Layers::InitCommands ( di ); | |
1498 | XDEDRAW_Props::InitCommands ( di ); | |
9ebaae37 | 1499 | XDEDRAW_GDTs::InitCommands ( di ); |
2df785d7 | 1500 | XDEDRAW_Views::InitCommands(di); |
024d6f77 | 1501 | XDEDRAW_Notes::InitCommands(di); |
7fd59977 | 1502 | XDEDRAW_Common::InitCommands ( di );//moved from EXE |
1503 | ||
1504 | } | |
1505 | ||
1506 | ||
1507 | //============================================================================== | |
1508 | // XDEDRAW::Factory | |
1509 | //============================================================================== | |
1510 | void XDEDRAW::Factory(Draw_Interpretor& theDI) | |
1511 | { | |
1512 | XSDRAWIGES::InitSelect(); | |
1513 | XSDRAWIGES::InitToBRep(theDI); | |
1514 | XSDRAWIGES::InitFromBRep(theDI); | |
1515 | ||
1516 | XSDRAWSTEP::InitCommands(theDI); | |
1517 | ||
7fd59977 | 1518 | XSDRAW::LoadDraw(theDI); |
1519 | ||
1520 | XDEDRAW::Init(theDI); | |
1521 | ||
0797d9d3 | 1522 | #ifdef OCCT_DEBUG |
586db386 | 1523 | theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n"; |
7fd59977 | 1524 | #endif |
1525 | } | |
1526 | ||
1527 | // Declare entry point PLUGINFACTORY | |
1528 | DPLUGIN(XDEDRAW) |