66585406826fb1dbb40a86c3f3390c9e21365833
[occt.git] / samples / mfc / standard / 06_Ocaf / src / OCAFSample_CommonDriver.cxx
1 // File:        OCAFSample_CommonDriver.cxx
2 // Created:     Wed Feb 13 18:24:21 2002
3 // Author:      Michael KUZMITCHEV
4 //              <mkv@russox.nnov.matra-dtv.fr>
5 //Modified by:  Sergey RUIN (Naming)
6
7 #include "stdafx.h"
8
9 #include <OCAFSample_CommonDriver.ixx>
10 #include <OCAFSample_ICommon.hxx>
11 #include <OCAFSample_IShape.hxx>
12
13 #include "Tags.h"
14
15 #include <BRepAlgoAPI_Common.hxx>
16 #include <TDF_Reference.hxx>
17 #include <TDocStd_Modified.hxx>
18 #include <TNaming_Builder.hxx>
19 #include <TNaming_NamedShape.hxx>
20 #include <TopoDS_Shape.hxx>
21
22 #include <BRepNaming_Common.hxx>
23
24 #include <TDataStd_TreeNode.hxx>
25 //#include <.hxx>
26
27 #include <BRepAlgo.hxx>
28
29 #define OK_OPERATION 0
30 #define TREENODE_NOT_FOUND 1
31 #define LABEL_NOT_FOUND 2
32 #define NAMED_SHAPE_NOT_FOUND 3
33 #define NAMED_SHAPE_EMPTY 4
34 #define OPERATION_NOT_DONE 8
35 #define NULL_OPERATION 9
36
37 // OCCT RTTI
38 IMPLEMENT_STANDARD_RTTIEXT (OCAFSample_CommonDriver, OCAFSample_Driver)
39
40 //=======================================================================
41 //function : Constructor
42 //purpose  :
43 //=======================================================================
44
45 OCAFSample_CommonDriver::OCAFSample_CommonDriver()
46 {
47 }
48
49 //=======================================================================
50 //function : Execute
51 //purpose  :
52 //=======================================================================
53
54 Standard_Integer OCAFSample_CommonDriver::Execute(Handle(TFunction_Logbook)& theLogbook) const
55 {
56   Handle(TDF_Reference) aReference;
57   TopoDS_Shape aMaster, aTool;
58
59   Handle(TDataStd_TreeNode) aNode;
60   if(!Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode)) return TREENODE_NOT_FOUND;
61
62   OCAFSample_ICommon anInterface(aNode);
63   aMaster = anInterface.GetContext();
64   aTool = anInterface.GetTool();
65
66   BRepAlgoAPI_Common mkCommon(aMaster, aTool);
67   if (!mkCommon.IsDone()) return OPERATION_NOT_DONE;
68   if (mkCommon.Shape().IsNull()) return NULL_OPERATION;
69   if (!BRepAlgo::IsValid(mkCommon.Shape()))
70           return OPERATION_NOT_DONE;
71
72
73   // Name result
74   TDF_Label ResultLabel = Label().FindChild(RESULTS_TAG);
75   
76   BRepNaming_Common aNaming(ResultLabel);
77   aNaming.Load(mkCommon);
78
79   OCAFSample_IShape::AddLabels(aNode, theLogbook);
80
81   TDocStd_Modified::Add(aNode->Father()->Label());
82
83   theLogbook->SetImpacted(Label());
84   TDocStd_Modified::Add(Label());  
85
86   theLogbook->SetImpacted(ResultLabel);
87
88   TDF_ChildIterator anIterator(ResultLabel);
89   for(; anIterator.More(); anIterator.Next()) {
90     theLogbook->SetImpacted(anIterator.Value());
91   }  
92
93   return OK_OPERATION;
94 }