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