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