2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_BooleanDriver.hxx>
5 #include <GEOMImpl_IBoolean.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepAlgo.hxx>
10 #include <BRepAlgoAPI_Common.hxx>
11 #include <BRepAlgoAPI_Cut.hxx>
12 #include <BRepAlgoAPI_Fuse.hxx>
13 #include <BRepAlgoAPI_Section.hxx>
14 #include <TopoDS_Shape.hxx>
16 #include <Standard_ConstructionError.hxx>
17 #include <StdFail_NotDone.hxx>
19 //=======================================================================
22 //=======================================================================
23 const Standard_GUID& GEOMImpl_BooleanDriver::GetID()
25 static Standard_GUID aBooleanDriver("FF1BBB21-5D14-4df2-980B-3A668264EA16");
26 return aBooleanDriver;
30 //=======================================================================
31 //function : GEOMImpl_BooleanDriver
33 //=======================================================================
34 GEOMImpl_BooleanDriver::GEOMImpl_BooleanDriver()
38 //=======================================================================
41 //=======================================================================
42 Standard_Integer GEOMImpl_BooleanDriver::Execute(TFunction_Logbook& log) const
44 if (Label().IsNull()) return 0;
45 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
47 GEOMImpl_IBoolean aCI (aFunction);
48 Standard_Integer aType = aFunction->GetType();
52 Handle(GEOM_Function) aRefShape1 = aCI.GetShape1();
53 Handle(GEOM_Function) aRefShape2 = aCI.GetShape2();
54 TopoDS_Shape aShape1 = aRefShape1->GetValue();
55 TopoDS_Shape aShape2 = aRefShape2->GetValue();
56 if (!aShape1.IsNull() && !aShape2.IsNull()) {
57 if (aType == BOOLEAN_COMMON) {
58 BRepAlgoAPI_Common BO (aShape1, aShape2);
61 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
64 } else if (aType == BOOLEAN_CUT) {
65 BRepAlgoAPI_Cut BO (aShape1, aShape2);
67 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
70 } else if (aType == BOOLEAN_FUSE) {
71 BRepAlgoAPI_Fuse BO (aShape1, aShape2);
73 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
76 } else if (aType == BOOLEAN_SECTION) {
77 BRepAlgoAPI_Section BO (aShape1, aShape2);
79 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
86 if (aShape.IsNull()) return 0;
87 if (!BRepAlgo::IsValid(aShape)) {
88 Standard_ConstructionError::Raise("Boolean aborted : non valid shape result");
91 aFunction->SetValue(aShape);
93 log.SetTouched(Label());
99 //=======================================================================
100 //function : GEOMImpl_BooleanDriver_Type_
102 //=======================================================================
103 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BooleanDriver_Type_()
106 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
107 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
108 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
109 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
110 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
111 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
114 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
115 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BooleanDriver",
116 sizeof(GEOMImpl_BooleanDriver),
118 (Standard_Address)_Ancestors,
119 (Standard_Address)NULL);
124 //=======================================================================
125 //function : DownCast
127 //=======================================================================
128 const Handle(GEOMImpl_BooleanDriver) Handle(GEOMImpl_BooleanDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
130 Handle(GEOMImpl_BooleanDriver) _anOtherObject;
132 if (!AnObject.IsNull()) {
133 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BooleanDriver))) {
134 _anOtherObject = Handle(GEOMImpl_BooleanDriver)((Handle(GEOMImpl_BooleanDriver)&)AnObject);
138 return _anOtherObject ;