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