1 // Copyright (c) 2020 OPEN CASCADE SAS
3 // This file is part of the examples of the Open CASCADE Technology software library.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
22 #include "OcafSamples.h"
24 #include "TOcaf_Application.h"
25 #include "TOcafFunction_BoxDriver.h"
26 #include "TOcafFunction_CylDriver.h"
28 #include <TPrsStd_AISViewer.hxx>
29 #include <AIS_InteractiveContext.hxx>
30 #include <AIS_DisplayMode.hxx>
31 #include <TPrsStd_AISPresentation.hxx>
32 #include <TNaming_NamedShape.hxx>
33 #include <TDataStd_Integer.hxx>
34 #include <TDataStd_Real.hxx>
35 #include <TDataStd_Name.hxx>
36 #include <TFunction_Function.hxx>
37 #include <TFunction_DriverTable.hxx>
38 #include <TDF_ChildIterator.hxx>
39 #include <PCDM_StoreStatus.hxx>
40 #include <BinDrivers.hxx>
41 #include <XmlDrivers.hxx>
43 void OcafSamples::Process (const TCollection_AsciiString& theSampleName)
45 if (IsImportSample(theSampleName))
51 myIsProcessed = Standard_False;
54 ExecuteSample(theSampleName);
58 TraceError(TCollection_AsciiString("Error in sample: ") + theSampleName);
62 void OcafSamples::ClearExtra()
65 myContext->RemoveAll(Standard_True);
68 void OcafSamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
70 Standard_Boolean anIsSamplePresent = Standard_True;
71 FindSourceCode(theSampleName);
72 if (theSampleName == "CreateOcafDocument")
74 else if (theSampleName == "CreateBoxOcafSample")
75 CreateBoxOcafSample();
76 else if (theSampleName == "CreateCylinderOcafSample")
77 CreateCylinderOcafSample();
78 else if (theSampleName == "ModifyBoxOcafSample")
79 ModifyBoxOcafSample();
80 else if (theSampleName == "ModifyCylinderOcafSample")
81 ModifyCylinderOcafSample();
82 else if (theSampleName == "UndoOcafSample")
84 else if (theSampleName == "RedoOcafSample")
86 else if (theSampleName == "DialogOpenOcafSample")
87 DialogOpenOcafSample();
88 else if (theSampleName == "DialogSaveBinOcafSample")
89 DialogSaveBinOcafSample();
90 else if (theSampleName == "DialogSaveXmlOcafSample")
91 DialogSaveXmlOcafSample();
94 myResult << "No function found: " << theSampleName;
95 myCode += TCollection_AsciiString("No function found: ") + theSampleName;
96 anIsSamplePresent = Standard_False;
98 myIsProcessed = anIsSamplePresent;
101 Standard_Boolean OcafSamples::IsExportSample (const TCollection_AsciiString& theSampleName)
103 if (theSampleName == "DialogSaveBinOcafSample" || theSampleName == "DialogSaveXmlOcafSample")
105 return Standard_True;
109 return Standard_False;
113 Standard_Boolean OcafSamples::IsImportSample (const TCollection_AsciiString& theSampleName)
115 if (theSampleName == "DialogOpenOcafSample")
117 return Standard_True;
121 return Standard_False;
125 Standard_Boolean OcafSamples::IsBinarySample (const TCollection_AsciiString& theSampleName)
127 if (theSampleName == "DialogOpenOcafSample" || theSampleName == "DialogSaveBinOcafSample")
129 return Standard_True;
133 return Standard_False;
137 Standard_Boolean OcafSamples::IsXmlSample (const TCollection_AsciiString& theSampleName)
139 if (theSampleName == "DialogOpenOcafSample" || theSampleName == "DialogSaveXmlOcafSample")
141 return Standard_True;
145 return Standard_False;
149 void OcafSamples::CreateOcafDocument()
151 Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
152 anOcaf_Application->NewDocument("BinOcaf", myOcafDoc);
153 TPrsStd_AISViewer::New(myOcafDoc->Main(), myViewer);
155 Handle(AIS_InteractiveContext) anAisContext;
156 TPrsStd_AISViewer::Find(myOcafDoc->Main(), anAisContext);
157 anAisContext->SetDisplayMode(AIS_Shaded, Standard_True);
158 myContext = anAisContext;
160 // Set the maximum number of available "undo" actions
161 myOcafDoc->SetUndoLimit(10);
164 void OcafSamples::CreateBoxOcafSample()
166 // Open a new command (for undo)
167 myOcafDoc->NewCommand();
169 // A data structure for our box:
170 // the box itself is attached to the BoxLabel label (as his name and his function attribute)
171 // its arguments (dimensions: width, length and height; and position: x, y, z)
172 // are attached to the child labels of the box:
173 // 0:1 Box Label ---> Name ---> Named shape ---> Function
174 // 0:1:1 -- Width Label
175 // 0:1:2 -- Length Label
176 // 0:1:3 -- Height Label
181 // Create a new label in the data structure for the box
182 TDF_Label aLabel = TDF_TagSource::NewChild(myOcafDoc->Main());
184 Standard_Real aBoxWidth(30.0), aBoxLength(20.0), aBoxHeight(10.0);
185 Standard_Real aBoxX(0.0), aBoxY(0.0), aBoxZ(0.0);
186 Standard_CString aBoxName("OcafBox");
187 // Create the data structure : Set the dimensions, position and name attributes
188 TDataStd_Real::Set(aLabel.FindChild(1), aBoxWidth);
189 TDataStd_Real::Set(aLabel.FindChild(2), aBoxLength);
190 TDataStd_Real::Set(aLabel.FindChild(3), aBoxHeight);
191 TDataStd_Real::Set(aLabel.FindChild(4), aBoxX);
192 TDataStd_Real::Set(aLabel.FindChild(5), aBoxY);
193 TDataStd_Real::Set(aLabel.FindChild(6), aBoxZ);
194 TDataStd_Name::Set(aLabel, aBoxName); // Name
196 // Instantiate a TFunction_Function attribute connected to the current box driver
197 // and attach it to the data structure as an attribute of the Box Label
198 Handle(TFunction_Function) myFunction = TFunction_Function::Set(aLabel, TOcafFunction_BoxDriver::GetID());
200 // Initialize and execute the box driver (look at the "Execute()" code)
201 Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
203 Handle(TFunction_Driver) myBoxDriver;
204 // Find the TOcafFunction_BoxDriver in the TFunction_DriverTable using its GUID
205 if (!TFunction_DriverTable::Get()->FindDriver(TOcafFunction_BoxDriver::GetID(), myBoxDriver))
207 myResult << "Ocaf Box driver not found" << std::endl;
210 myBoxDriver->Init(aLabel);
211 if (myBoxDriver->Execute(aLogBook))
213 myResult << "Create Box function execute failed" << std::endl;
216 // Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
217 Handle(TPrsStd_AISPresentation) anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
219 anAisPresentation->Display(1);
220 // Attach an integer attribute to aLabel to memorize it's displayed
221 TDataStd_Integer::Set(aLabel, 1);
222 myContext->UpdateCurrentViewer();
224 // Close the command (for undo)
225 myOcafDoc->CommitCommand();
227 myResult << "Created a box with name: " << aBoxName << std::endl;
228 myResult << "base coord X: " << aBoxX << " Y: " << aBoxY << " Z: " << aBoxZ << std::endl;
229 myResult << "width: " << aBoxWidth << " length: " << aBoxLength << " height: " << aBoxHeight << std::endl;
232 void OcafSamples::CreateCylinderOcafSample()
234 // Open a new command (for undo)
235 myOcafDoc->NewCommand();
237 // A data structure for our cylinder:
238 // the cylinder itself is attached to the CylinderLabel label (as his name and his function attribute)
239 // its arguments (dimensions: radius and height; and position: x, y, z)
240 // are attached to the child labels of the cylinder:
241 // 0:1 Cylinder Label ---> Name ---> Named shape ---> Function
242 // 0:1:1 -- Radius Label
243 // 0:1:2 -- Height Label
248 // Create a new label in the data structure for the cylinder
249 TDF_Label aLabel = TDF_TagSource::NewChild(myOcafDoc->Main());
251 Standard_Real aCylRadius(10.0), aCylHeight(20.0);
252 Standard_Real aCylX(60.0), aCylY(40.0), aCylZ(0.0);
253 Standard_CString aCylName("OcafCylinder");
254 // Create the data structure : Set the dimensions, position and name attributes
255 TDataStd_Real::Set(aLabel.FindChild(1), aCylRadius);
256 TDataStd_Real::Set(aLabel.FindChild(2), aCylHeight);
257 TDataStd_Real::Set(aLabel.FindChild(3), aCylX);
258 TDataStd_Real::Set(aLabel.FindChild(4), aCylY);
259 TDataStd_Real::Set(aLabel.FindChild(5), aCylZ);
260 TDataStd_Name::Set(aLabel, aCylName);
262 // Instantiate a TFunction_Function attribute connected to the current cylinder driver
263 // and attach it to the data structure as an attribute of the Cylinder Label
264 Handle(TFunction_Function) myFunction = TFunction_Function::Set(aLabel, TOcafFunction_CylDriver::GetID());
266 // Initialize and execute the cylinder driver (look at the "Execute()" code)
267 Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
269 Handle(TFunction_Driver) myCylDriver;
270 // Find the TOcafFunction_CylDriver in the TFunction_DriverTable using its GUID
271 if (!TFunction_DriverTable::Get()->FindDriver(TOcafFunction_CylDriver::GetID(), myCylDriver))
273 myResult << "Ocaf Cylinder driver not found";
275 myCylDriver->Init(aLabel);
276 if (myCylDriver->Execute(aLogBook))
278 myResult << "Create Cylinder function execute failed";
280 // Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
281 Handle(TPrsStd_AISPresentation) anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
283 anAisPresentation->Display(1);
284 // Attach an integer attribute to aLabel to memorize it's displayed
285 TDataStd_Integer::Set(aLabel, 1);
286 myContext->UpdateCurrentViewer();
288 // Close the command (for undo)
289 myOcafDoc->CommitCommand();
291 myResult << "Created a cylinder with name: " << aCylName << std::endl;
292 myResult << "radius: " << aCylRadius << " height: " << aCylHeight << std::endl;
293 myResult << "base coord X: " << aCylX << " Y: " << aCylY << " Z: " << aCylZ << std::endl;
296 void OcafSamples::ModifyBoxOcafSample()
298 AIS_ListOfInteractive anAisObjectsList;
299 myContext->DisplayedObjects(anAisObjectsList);
300 Standard_Integer aBoxCount(0);
301 for(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList);
302 anIter.More(); anIter.Next())
304 const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value();
306 // Get the main label of the selected object
307 Handle(TPrsStd_AISPresentation) anAisPresentation = Handle(TPrsStd_AISPresentation)::DownCast(anAisObject->GetOwner());
308 TDF_Label aLabel = anAisPresentation->Label();
310 // Get the TFunction_Function attribute of the selected object
311 Handle(TFunction_Function) aFunction;
312 if (!aLabel.FindAttribute(TFunction_Function::GetID(), aFunction))
314 myResult << "Object cannot be modify.";
317 // Get the Standard_GUID of the TFunction_FunctionDriver of the selected object TFunction_Function attribute
318 Standard_GUID aDriverID = aFunction->GetDriverGUID();
320 // Case of a box created with the box function driver
321 if (aDriverID == TOcafFunction_BoxDriver::GetID())
324 Standard_Real aBoxX, aBoxY, aBoxZ, aBoxWidth, aBoxLength, aBoxHeight;
326 // Get the attributes values of the current box
327 Handle(TDataStd_Real) aCurrentReal;
328 aLabel.FindChild(1).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
329 aBoxWidth = aCurrentReal->Get();
330 aLabel.FindChild(2).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
331 aBoxLength = aCurrentReal->Get();
332 aLabel.FindChild(3).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
333 aBoxHeight = aCurrentReal->Get();
334 aLabel.FindChild(4).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
335 aBoxX = aCurrentReal->Get();
336 aLabel.FindChild(5).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
337 aBoxY = aCurrentReal->Get();
338 aLabel.FindChild(6).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
339 aBoxZ = aCurrentReal->Get();
340 Handle(TDataStd_Name) aBoxName;
341 aLabel.FindAttribute(TDataStd_Name::GetID(), aBoxName);
343 myResult << "Current parameters of box with name: " << aBoxName->Get() << std::endl;
344 myResult << "width: " << aBoxWidth << " length: " << aBoxLength << " height: " << aBoxHeight << std::endl;
345 myResult << "base coord X: " << aBoxX << " Y: " << aBoxY << " Z: " << aBoxZ << std::endl;
347 // Open a new command (for undo)
348 myOcafDoc->NewCommand();
349 // Modify the box - 1.5 times increase
350 aBoxWidth *= 1.5; aBoxLength *= 1.5; aBoxHeight *= 1.5;
352 TDataStd_Real::Set(aLabel.FindChild(1), aBoxWidth);
353 TDataStd_Real::Set(aLabel.FindChild(2), aBoxLength);
354 TDataStd_Real::Set(aLabel.FindChild(3), aBoxHeight);
355 TDataStd_Real::Set(aLabel.FindChild(4), aBoxX);
356 TDataStd_Real::Set(aLabel.FindChild(5), aBoxY);
357 TDataStd_Real::Set(aLabel.FindChild(6), aBoxZ);
359 // Get the TFunction_FunctionDriver GUID used with the TFunction_Function
360 aDriverID = aFunction->GetDriverGUID();
361 Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
362 Handle(TFunction_Driver) aBoxDriver;
363 // Find the TOcafFunction_BoxDriver in the TFunction_DriverTable using its GUID
364 TFunction_DriverTable::Get()->FindDriver(aDriverID, aBoxDriver);
365 // Execute the cut if it must be (if an attribute changes)
366 aBoxDriver->Init(aLabel);
368 // Set the box touched, it will be useful to recompute an object which used this box as attribute
369 aLogBook->SetTouched(aLabel);
370 if (aBoxDriver->Execute(aLogBook))
372 myResult << "Recompute failed" << std::endl;
375 // Get the presentation of the box, display it and set it selected
376 anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
377 TDataStd_Integer::Set(aLabel, 1);
378 anAisPresentation->Display(1);
379 myContext->UpdateCurrentViewer();
380 // Close the command (for undo)
381 myOcafDoc->CommitCommand();
383 myResult << std::endl;
384 myResult << "New box parameters: " << std::endl;
385 myResult << "base coord X: " << aBoxX << " Y: " << aBoxY << " Z: " << aBoxZ << std::endl;
386 myResult << "width: " << aBoxWidth << " length: " << aBoxLength << " height: " << aBoxHeight << std::endl;
391 myResult << "Number of modified boxes: " << aBoxCount << std::endl;
395 myResult << "No boxes to modify" << std::endl;
399 void OcafSamples::ModifyCylinderOcafSample()
401 AIS_ListOfInteractive anAisObjectsList;
402 myContext->DisplayedObjects(anAisObjectsList);
403 Standard_Integer aCylCount(0);
404 for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList);
405 anIter.More(); anIter.Next())
407 const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value();
408 // Get the main label of the selected object
409 Handle(TPrsStd_AISPresentation) anAisPresentation = Handle(TPrsStd_AISPresentation)::DownCast(anAisObject->GetOwner());
410 TDF_Label aLabel = anAisPresentation->Label();
412 // Get the TFunction_Function attribute of the selected object
413 Handle(TFunction_Function) aFunction;
414 if (!aLabel.FindAttribute(TFunction_Function::GetID(), aFunction))
416 myResult << "Object cannot be modify.";
419 // Get the Standard_GUID of the TFunction_FunctionDriver of the selected object TFunction_Function attribute
420 Standard_GUID aDriverID = aFunction->GetDriverGUID();
422 // Case of a box created with the box function driver
423 if (aDriverID == TOcafFunction_CylDriver::GetID())
426 Standard_Real aCylRadius, aCylHeight, aCylX, aCylY, aCylZ;
428 // Get the attributes values of the current box
429 Handle(TDataStd_Real) aCurrentReal;
430 aLabel.FindChild(1).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
431 aCylRadius = aCurrentReal->Get();
432 aLabel.FindChild(2).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
433 aCylHeight = aCurrentReal->Get();
434 aLabel.FindChild(3).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
435 aCylX = aCurrentReal->Get();
436 aLabel.FindChild(4).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
437 aCylY = aCurrentReal->Get();
438 aLabel.FindChild(5).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
439 aCylZ = aCurrentReal->Get();
441 Handle(TDataStd_Name) aCylName;
442 aLabel.FindAttribute(TDataStd_Name::GetID(), aCylName);
444 myResult << "Current parameters of box with name: " << aCylName->Get() << std::endl;
445 myResult << "radius: " << aCylRadius << " height: " << aCylHeight << std::endl;
446 myResult << "base coord X: " << aCylX << " Y: " << aCylY << " Z: " << aCylZ << std::endl;
448 // Open a new command (for undo)
449 myOcafDoc->NewCommand();
450 // Modify the cylinder - 2x increase
451 aCylRadius *= 2.0; aCylHeight *= 2.0;
452 // and move base point in XY plane
453 aCylX *= 2.0; aCylY *= 2.0;
455 TDataStd_Real::Set(aLabel.FindChild(1), aCylRadius);
456 TDataStd_Real::Set(aLabel.FindChild(2), aCylHeight);
457 TDataStd_Real::Set(aLabel.FindChild(3), aCylX);
458 TDataStd_Real::Set(aLabel.FindChild(4), aCylY);
459 TDataStd_Real::Set(aLabel.FindChild(5), aCylZ);
461 // Get the TFunction_FunctionDriver GUID used with the TFunction_Function
462 aDriverID = aFunction->GetDriverGUID();
463 Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
464 Handle(TFunction_Driver) aCylDriver;
465 // Find the TOcafFunction_CylDriver in the TFunction_DriverTable using its GUID
466 TFunction_DriverTable::Get()->FindDriver(aDriverID, aCylDriver);
467 // Execute the cut if it must be (if an attribute changes)
468 aCylDriver->Init(aLabel);
470 // Set the cylinder touched, it will be useful to recompute an object which used this box as attribute
471 aLogBook->SetTouched(aLabel);
472 if (aCylDriver->Execute(aLogBook))
474 myResult << "Recompute failed" << std::endl;
476 // Get the presentation of the box, display it and set it selected
477 anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
478 TDataStd_Integer::Set(aLabel, 1);
479 anAisPresentation->Display(1);
480 myContext->UpdateCurrentViewer();
481 // Close the command (for undo)
482 myOcafDoc->CommitCommand();
484 myResult << std::endl;
485 myResult << "New cylinder parameters: " << std::endl;
486 myResult << "radius: " << aCylRadius << " height: " << aCylHeight << std::endl;
487 myResult << "base coord X: " << aCylX << " Y: " << aCylY << " Z: " << aCylZ << std::endl;
492 myResult << "Number of modified boxes: " << aCylCount << std::endl;
496 myResult << "No boxes to modify" << std::endl;
500 void OcafSamples::UndoOcafSample()
502 if (myOcafDoc->Undo())
504 myOcafDoc->CommitCommand();
505 myContext->UpdateCurrentViewer();
506 myResult << "Undo was done successfully" << std::endl;
510 myResult << "Nothing to undo" << std::endl;
514 void OcafSamples::RedoOcafSample()
516 if (myOcafDoc->Redo())
518 myOcafDoc->CommitCommand();
519 myContext->UpdateCurrentViewer();
520 myResult << "Redo was done successfully" << std::endl;
524 myResult << "Nothing to redo" << std::endl;
528 void OcafSamples::DialogOpenOcafSample()
530 Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
532 BinDrivers::DefineFormat(anOcaf_Application);
533 XmlDrivers::DefineFormat(anOcaf_Application);
534 // Look for already opened
535 if (anOcaf_Application->IsInSession(myFileName))
537 myResult << "Document: " << myFileName << " is already in session" << std::endl;
540 // Open the document in the current application
541 PCDM_ReaderStatus aReaderStatus = anOcaf_Application->Open(myFileName, myOcafDoc);
542 if (aReaderStatus == PCDM_RS_OK)
544 // Connect the document CAF (myDoc) with the AISContext (myAISContext)
545 TPrsStd_AISViewer::New(myOcafDoc->Main(), myViewer);
546 myOcafDoc->SetUndoLimit(10);
548 myContext->RemoveAll(Standard_False);
549 Handle(AIS_InteractiveContext) aContext;
550 TPrsStd_AISViewer::Find(myOcafDoc->Main(), aContext);
551 aContext->SetDisplayMode(AIS_Shaded, Standard_True);
552 myContext = aContext;
554 // Display the presentations (which was not stored in the document)
555 DisplayPresentation();
556 myResult << "Open a document" << std::endl;
560 myResult << "Error! The file wasn't opened. PCDM_ReaderStatus: " << aReaderStatus << std::endl;
564 void OcafSamples::DialogSaveBinOcafSample()
566 Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
567 BinDrivers::DefineFormat(anOcaf_Application);
568 myOcafDoc->ChangeStorageFormat("BinOcaf");
569 // Saves the document in the current application
570 PCDM_StoreStatus aStoreStatus = anOcaf_Application->SaveAs(myOcafDoc, myFileName);
571 if (aStoreStatus == PCDM_SS_OK)
573 myResult << "The file was saved successfully" << std::endl;
577 myResult << "Error! The file wasn't saved. PCDM_StoreStatus: " << aStoreStatus << std::endl;
581 void OcafSamples::DialogSaveXmlOcafSample()
583 Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
584 XmlDrivers::DefineFormat(anOcaf_Application);
585 myOcafDoc->ChangeStorageFormat("XmlOcaf");
586 // Saves the document in the current application
587 PCDM_StoreStatus aStoreStatus = anOcaf_Application->SaveAs(myOcafDoc, myFileName);
588 if (aStoreStatus == PCDM_SS_OK)
590 myResult << "The file was saved successfully" << std::endl;
594 myResult << "Error! The file wasn't saved. PCDM_StoreStatus: " << aStoreStatus << std::endl;
598 void OcafSamples::DisplayPresentation()
600 TDF_Label aRootlabel = myOcafDoc->Main();
602 for (TDF_ChildIterator it(aRootlabel); it.More(); it.Next())
604 TDF_Label aLabel = it.Value();
605 Handle(TNaming_NamedShape) aNamedShape;
606 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape))
610 Handle(TDataStd_Integer) aDataInteger;
612 // To know if the object was displayed
613 if (aLabel.FindAttribute(TDataStd_Integer::GetID(), aDataInteger))
615 if (!aDataInteger->Get())
620 Handle(TPrsStd_AISPresentation) anAisPresentation;
621 if (!aLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), anAisPresentation))
623 anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
625 anAisPresentation->SetColor(Quantity_NOC_ORANGE);
626 anAisPresentation->Display(1);
628 myContext->UpdateCurrentViewer();