3 #include "GEOMImpl_BooleanDriver.hxx"
4 #include "GEOMImpl_IBoolean.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepAlgo.hxx>
9 #include <BRepAlgoAPI_Common.hxx>
10 #include <BRepAlgoAPI_Cut.hxx>
11 #include <BRepAlgoAPI_Fuse.hxx>
12 #include <BRepAlgoAPI_Section.hxx>
13 #include <TopoDS_Shape.hxx>
15 #include <Standard_ConstructionError.hxx>
16 #include <StdFail_NotDone.hxx>
18 //=======================================================================
21 //=======================================================================
22 const Standard_GUID& GEOMImpl_BooleanDriver::GetID()
24 static Standard_GUID aBooleanDriver("FF1BBB21-5D14-4df2-980B-3A668264EA16");
25 return aBooleanDriver;
29 //=======================================================================
30 //function : GEOMImpl_BooleanDriver
32 //=======================================================================
33 GEOMImpl_BooleanDriver::GEOMImpl_BooleanDriver()
37 //=======================================================================
40 //=======================================================================
41 Standard_Integer GEOMImpl_BooleanDriver::Execute(TFunction_Logbook& log) const
43 if (Label().IsNull()) return 0;
44 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
46 GEOMImpl_IBoolean aCI (aFunction);
47 Standard_Integer aType = aFunction->GetType();
51 Handle(GEOM_Function) aRefShape1 = aCI.GetShape1();
52 Handle(GEOM_Function) aRefShape2 = aCI.GetShape2();
53 TopoDS_Shape aShape1 = aRefShape1->GetValue();
54 TopoDS_Shape aShape2 = aRefShape2->GetValue();
55 if (!aShape1.IsNull() && !aShape2.IsNull()) {
56 if (aType == BOOLEAN_COMMON) {
57 BRepAlgoAPI_Common BO (aShape1, aShape2);
60 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
63 } else if (aType == BOOLEAN_CUT) {
64 BRepAlgoAPI_Cut BO (aShape1, aShape2);
66 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
69 } else if (aType == BOOLEAN_FUSE) {
70 BRepAlgoAPI_Fuse BO (aShape1, aShape2);
72 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
75 } else if (aType == BOOLEAN_SECTION) {
76 BRepAlgoAPI_Section BO (aShape1, aShape2);
78 StdFail_NotDone::Raise("Requested boolean operation can not be performed on the given shapes");
85 if (aShape.IsNull()) return 0;
86 if (!BRepAlgo::IsValid(aShape)) {
87 Standard_ConstructionError::Raise("Boolean aborted : non valid shape result");
90 aFunction->SetValue(aShape);
92 log.SetTouched(Label());
98 //=======================================================================
99 //function : GEOMImpl_BooleanDriver_Type_
101 //=======================================================================
102 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BooleanDriver_Type_()
105 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
106 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
107 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
108 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
109 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
110 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
113 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
114 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BooleanDriver",
115 sizeof(GEOMImpl_BooleanDriver),
117 (Standard_Address)_Ancestors,
118 (Standard_Address)NULL);
123 //=======================================================================
124 //function : DownCast
126 //=======================================================================
127 const Handle(GEOMImpl_BooleanDriver) Handle(GEOMImpl_BooleanDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
129 Handle(GEOMImpl_BooleanDriver) _anOtherObject;
131 if (!AnObject.IsNull()) {
132 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BooleanDriver))) {
133 _anOtherObject = Handle(GEOMImpl_BooleanDriver)((Handle(GEOMImpl_BooleanDriver)&)AnObject);
137 return _anOtherObject ;