Back to index

salome-geom  6.5.0
GEOMImpl_BoxDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_BoxDriver.hxx>
00026 #include <GEOMImpl_IBox.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <BRepPrimAPI_MakeBox.hxx>
00031 #include <BRep_Tool.hxx>
00032 #include <gp_Pnt.hxx>
00033 #include <TopoDS.hxx>
00034 #include <TopoDS_Shape.hxx>
00035 #include <TopoDS_Vertex.hxx>
00036 #include <TopAbs.hxx>
00037 
00038 #include <StdFail_NotDone.hxx>
00039 
00040 #include <Precision.hxx>
00041 
00042 #include<cmath>
00043 
00044 //=======================================================================
00045 //function : GetID
00046 //purpose  :
00047 //=======================================================================
00048 const Standard_GUID& GEOMImpl_BoxDriver::GetID()
00049 {
00050   static Standard_GUID aBoxDriver("FF1BBB13-5D14-4df2-980B-3A668264EA16");
00051   return aBoxDriver;
00052 }
00053 
00054 
00055 //=======================================================================
00056 //function : GEOMImpl_BoxDriver
00057 //purpose  :
00058 //=======================================================================
00059 GEOMImpl_BoxDriver::GEOMImpl_BoxDriver()
00060 {
00061 }
00062 
00063 //=======================================================================
00064 //function : Execute
00065 //purpose  :
00066 //=======================================================================
00067 Standard_Integer GEOMImpl_BoxDriver::Execute(TFunction_Logbook& log) const
00068 {
00069   if (Label().IsNull()) return 0;
00070   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00071 
00072   GEOMImpl_IBox aBI (aFunction);
00073   Standard_Integer aType = aFunction->GetType();
00074 
00075   TopoDS_Shape aShape;
00076 
00077   if (aType == BOX_DX_DY_DZ) {
00078     BRepPrimAPI_MakeBox MB (aBI.GetDX(), aBI.GetDY(), aBI.GetDZ());
00079     MB.Build();
00080 
00081     if (!MB.IsDone()) {
00082       StdFail_NotDone::Raise("Box with the given dimensions can not be computed");
00083     }
00084     aShape = MB.Shape();
00085   }
00086   else if (aType == BOX_TWO_PNT) {
00087     Handle(GEOM_Function) aRefPoint1 = aBI.GetRef1();
00088     Handle(GEOM_Function) aRefPoint2 = aBI.GetRef2();
00089     TopoDS_Shape aShape1 = aRefPoint1->GetValue();
00090     TopoDS_Shape aShape2 = aRefPoint2->GetValue();
00091     if (aShape1.ShapeType() == TopAbs_VERTEX &&
00092         aShape2.ShapeType() == TopAbs_VERTEX) {
00093       gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
00094       gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
00095 
00096       if (std::abs(P1.X() - P2.X()) < Precision::Confusion() || 
00097           std::abs(P1.Y() - P2.Y()) < Precision::Confusion() || 
00098           std::abs(P1.Z() - P2.Z()) < Precision::Confusion() ) {
00099         StdFail_NotDone::Raise("Box can not be created, the points belong both to one of the OXY, OYZ or OZX planes");
00100         return 0;
00101       }
00102 
00103       BRepPrimAPI_MakeBox MB (P1,P2);
00104       MB.Build();
00105 
00106       if (!MB.IsDone()) {
00107         StdFail_NotDone::Raise("Box can not be computed from the given point");
00108       }
00109       aShape = MB.Shape();
00110     }
00111   }
00112   else {
00113   }
00114 
00115   if (aShape.IsNull()) return 0;
00116 
00117   aFunction->SetValue(aShape);
00118 
00119   log.SetTouched(Label());
00120 
00121   return 1;
00122 }
00123 
00124 
00125 //=======================================================================
00126 //function :  GEOMImpl_BoxDriver_Type_
00127 //purpose  :
00128 //=======================================================================
00129 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BoxDriver_Type_()
00130 {
00131 
00132   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00133   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00134   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00135   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00136   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00137   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00138 
00139 
00140   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00141   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BoxDriver",
00142                                                          sizeof(GEOMImpl_BoxDriver),
00143                                                          1,
00144                                                          (Standard_Address)_Ancestors,
00145                                                          (Standard_Address)NULL);
00146 
00147   return _aType;
00148 }
00149 
00150 //=======================================================================
00151 //function : DownCast
00152 //purpose  :
00153 //=======================================================================
00154 const Handle(GEOMImpl_BoxDriver) Handle(GEOMImpl_BoxDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00155 {
00156   Handle(GEOMImpl_BoxDriver) _anOtherObject;
00157 
00158   if (!AnObject.IsNull()) {
00159      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BoxDriver))) {
00160        _anOtherObject = Handle(GEOMImpl_BoxDriver)((Handle(GEOMImpl_BoxDriver)&)AnObject);
00161      }
00162   }
00163 
00164   return _anOtherObject ;
00165 }