1 // File: TOcafFunction_CutDriver.cxx
2 // Created: Mon Dec 27 10:37:13 1999
3 // Author: Vladislav ROMASHKO
4 // <vro@flox.nnov.matra-dtv.fr>
8 #include <TOcafFunction_CutDriver.hxx>
10 #include <TNaming_NamedShape.hxx>
11 #include <TNaming_Builder.hxx>
13 #include <BRepAlgoAPI_Cut.hxx>
14 #include <TCollection_AsciiString.hxx>
15 #include <TDF_Tool.hxx>
17 //=======================================================================
20 //=======================================================================
22 const Standard_GUID& TOcafFunction_CutDriver::GetID() {
23 static Standard_GUID anID("22D22E52-D69A-11d4-8F1A-0060B0EE18E8");
28 //=======================================================================
29 //function : TPartStd_CutDriver
30 //purpose : Creation of an instance of the driver. It's possible (and recommended)
31 // : to have only one instance of a driver for the whole session.
32 //=======================================================================
34 TOcafFunction_CutDriver::TOcafFunction_CutDriver()
37 //=======================================================================
39 //purpose : Validation of the object label, its arguments and its results.
40 //=======================================================================
42 void TOcafFunction_CutDriver::Validate(TFunction_Logbook& log) const
44 // We validate the object label ( Label() ), all the arguments and the results of the object:
45 log.SetValid(Label(), Standard_True);
48 //=======================================================================
49 //function : MustExecute
50 //purpose : We call this method to check if the object was modified to
51 // : be invoked. If the object label or an argument is modified,
52 // : we must recompute the object - to call the method Execute().
53 //=======================================================================
55 Standard_Boolean TOcafFunction_CutDriver::MustExecute(const TFunction_Logbook& log) const
57 // If the object's label is modified:
58 if (log.IsModified(Label())) return Standard_True;
60 // Cut (in our simple case) has two arguments: The original shape, and the tool shape.
61 // They are on the child labels of the cut's label:
62 // So, OriginalNShape - is attached to the first child label
63 // ToolNShape - is attached to the second child label,
66 Handle(TDF_Reference) OriginalRef;
67 //TDF_Label aLabel = Label().FindChild(1);
69 BOOL f = Label().IsNull();
70 int a = Label().NbChildren();
72 TCollection_AsciiString aEntry;
73 TDF_Tool::Entry(Label(), aEntry);
74 cout << "Entry: "<<aEntry.ToCString()<<endl;
75 Label().FindChild(1).FindAttribute(TDF_Reference::GetID(),OriginalRef);
76 if (log.IsModified(OriginalRef->Get())) return Standard_True; // Original shape.
78 Handle(TDF_Reference) ToolRef;
79 Label().FindChild(2).FindAttribute(TDF_Reference::GetID(),ToolRef);
80 if (log.IsModified(ToolRef->Get())) return Standard_True; // Tool shape.
82 // if there are no any modifications concerned the cut,
83 // it's not necessary to recompute (to call the method Execute()):
84 return Standard_False;
87 //=======================================================================
90 // : We compute the object and topologically name it.
91 // : If during the execution we found something wrong,
92 // : we return the number of the failure. For example:
93 // : 1 - an attribute hasn't been found,
94 // : 2 - algorithm failed,
95 // : if there are no any mistakes occurred we return 0:
96 // : 0 - no mistakes were found.
97 //=======================================================================
99 Standard_Integer TOcafFunction_CutDriver::Execute(TFunction_Logbook& log) const
101 // Let's get the arguments (OriginalNShape, ToolNShape of the object):
103 // First, we have to retrieve the TDF_Reference attributes to obtain the root labels of the OriginalNShape and the ToolNShape:
104 Handle(TDF_Reference) OriginalRef, ToolRef;
105 if (!Label().FindChild(1).FindAttribute(TDF_Reference::GetID(), OriginalRef )) return 1;
106 TDF_Label OriginalLab = OriginalRef->Get();
107 if (!Label().FindChild(2).FindAttribute(TDF_Reference::GetID(), ToolRef)) return 1;
108 TDF_Label ToolLab = ToolRef->Get();
110 // Get the TNaming_NamedShape attributes of these labels
111 Handle(TNaming_NamedShape) OriginalNShape, ToolNShape;
112 if (!( OriginalLab.FindAttribute(TNaming_NamedShape::GetID(),OriginalNShape) ))
113 Standard_Failure::Raise("TOcaf_Commands::CutObjects");
114 if (!( ToolLab.FindAttribute(TNaming_NamedShape::GetID(),ToolNShape) ))
115 Standard_Failure::Raise("TOcaf_Commands::CutObjects");
117 // Now, let's get the TopoDS_Shape of these TNaming_NamedShape:
118 TopoDS_Shape OriginalShape = OriginalNShape->Get();
119 TopoDS_Shape ToolShape = ToolNShape->Get();
122 // Let's call for algorithm computing a cut operation:
123 BRepAlgoAPI_Cut mkCut(OriginalShape, ToolShape);
124 // Let's check if the Cut has been successfull:
127 MessageBox(0,"Cut not done.","Cut Function Driver",MB_ICONERROR);
130 TopoDS_Shape ResultShape = mkCut.Shape();
132 // Build a TNaming_NamedShape using built cut
133 TNaming_Builder B(Label());
134 B.Modify( OriginalShape, ResultShape);
136 // If there are no any mistakes we return 0:
140 TOcafFunction_CutDriver::~TOcafFunction_CutDriver() {}
144 Standard_EXPORT Handle_Standard_Type& TOcafFunction_CutDriver_Type_()
147 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
148 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
149 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
150 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
151 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
152 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
155 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
156 static Handle_Standard_Type _aType = new Standard_Type("TOcafFunction_CutDriver",
157 sizeof(TOcafFunction_CutDriver),
159 (Standard_Address)_Ancestors,
160 (Standard_Address)NULL);
167 // allow safe downcasting
169 const Handle(TOcafFunction_CutDriver) Handle(TOcafFunction_CutDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
171 Handle(TOcafFunction_CutDriver) _anOtherObject;
173 if (!AnObject.IsNull()) {
174 if (AnObject->IsKind(STANDARD_TYPE(TOcafFunction_CutDriver))) {
175 _anOtherObject = Handle(TOcafFunction_CutDriver)((Handle(TOcafFunction_CutDriver)&)AnObject);
179 return _anOtherObject ;
181 const Handle(Standard_Type)& TOcafFunction_CutDriver::DynamicType() const
183 return STANDARD_TYPE(TOcafFunction_CutDriver) ;
185 Standard_Boolean TOcafFunction_CutDriver::IsKind(const Handle(Standard_Type)& AType) const
187 return (STANDARD_TYPE(TOcafFunction_CutDriver) == AType || TFunction_Driver::IsKind(AType));
190 Handle_TOcafFunction_CutDriver::~Handle_TOcafFunction_CutDriver() {}