Back to index

salome-geom  6.5.0
GEOMImpl_PositionDriver.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_PositionDriver.hxx>
00026 #include <GEOMImpl_IPosition.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <GEOMImpl_IMeasureOperations.hxx>
00031 
00032 // OCCT Includes
00033 #include <BRepBuilderAPI_Transform.hxx>
00034 #include <ShHealOper_EdgeDivide.hxx>
00035 #include <BRep_Tool.hxx>
00036 #include <BRepTools.hxx>
00037 #include <BRepFill_LocationLaw.hxx>
00038 #include <BRepFill_Edge3DLaw.hxx>
00039 #include <BRepFill_SectionPlacement.hxx>
00040 #include <BRepTools_WireExplorer.hxx>
00041 #include <BRepBuilderAPI_MakeWire.hxx>
00042 #include <BRepBuilderAPI_MakeVertex.hxx>
00043 #include <TopoDS.hxx>
00044 #include <TopoDS_Shape.hxx>
00045 #include <TopoDS_Vertex.hxx>
00046 #include <TopoDS_Edge.hxx>
00047 #include <TopoDS_Wire.hxx>
00048 #include <TopAbs.hxx>
00049 #include <TopExp.hxx>
00050 #include <TopExp_Explorer.hxx>
00051 #include <gp_Pln.hxx>
00052 #include <Geom_Plane.hxx>
00053 #include <Geom_Curve.hxx>
00054 #include <GProp_GProps.hxx>
00055 #include <BRepGProp.hxx>
00056 #include <ShapeAnalysis_Edge.hxx>
00057 #include <GeomAdaptor_Curve.hxx>
00058 #include <BRepGProp.hxx>
00059 #include <ShapeFix_Wire.hxx>
00060 
00061 #include <GeomFill_TrihedronLaw.hxx>
00062 #include <GeomFill_CurveAndTrihedron.hxx>
00063 #include <GeomFill_CorrectedFrenet.hxx>
00064 
00065 #include <Precision.hxx>
00066 #include <gp_Pnt.hxx>
00067 #include <gp_Vec.hxx>
00068 #include <TopExp.hxx>
00069 
00070 //=======================================================================
00071 //function : GetID
00072 //purpose  :
00073 //=======================================================================
00074 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
00075 {
00076   static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
00077   return aPositionDriver;
00078 }
00079 
00080 
00081 //=======================================================================
00082 //function : GEOMImpl_PositionDriver
00083 //purpose  :
00084 //=======================================================================
00085 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
00086 {
00087 }
00088 
00089 //=======================================================================
00090 //function : Execute
00091 //purpose  :
00092 //=======================================================================
00093 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
00094 {
00095   if (Label().IsNull()) return 0;
00096   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00097 
00098   GEOMImpl_IPosition aCI (aFunction);
00099   Standard_Integer aType = aFunction->GetType();
00100 
00101   TopoDS_Shape aShape;
00102 
00103   if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
00104     Handle(GEOM_Function) aRefShape = aCI.GetShape();
00105     Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
00106     Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
00107 
00108     TopoDS_Shape aShapeBase = aRefShape->GetValue();
00109     TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
00110     TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
00111 
00112     if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
00113         aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
00114       return 0;
00115 
00116     gp_Trsf aTrsf;
00117     gp_Ax3 aStartAx3, aDestAx3;
00118 
00119     // End LCS
00120     aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
00121 
00122     // Start LCS
00123     aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);
00124 
00125     // Set transformation
00126     aTrsf.SetDisplacement(aStartAx3, aDestAx3);
00127 
00128     // Perform transformation
00129     BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
00130     aShape = aBRepTrsf.Shape();
00131   }
00132   else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
00133            aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
00134     Handle(GEOM_Function) aRefShape = aCI.GetShape();
00135     Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
00136 
00137     TopoDS_Shape aShapeBase = aRefShape->GetValue();
00138     TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
00139 
00140     if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
00141         aShapeEndLCS.ShapeType() != TopAbs_FACE)
00142       return 0;
00143 
00144     gp_Trsf aTrsf;
00145     gp_Ax3 aStartAx3, aDestAx3;
00146 
00147     // End LCS
00148     aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
00149 
00150     // Set transformation
00151     aTrsf.SetDisplacement(aStartAx3, aDestAx3);
00152 
00153     // Perform transformation
00154     BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
00155     aShape = aBRepTrsf.Shape();
00156   }
00157   else if (aType == POSITION_ALONG_PATH) {
00158     Handle(GEOM_Function) aRefShape = aCI.GetShape();
00159     Handle(GEOM_Function) aPathShape = aCI.GetPath();
00160     Standard_Real aParameter = aCI.GetDistance();
00161     bool aReversed = aCI.GetReverse();
00162     if (aReversed)
00163       aParameter = 1 - aParameter;
00164 
00165     TopoDS_Shape aShapeBase = aRefShape->GetValue();
00166     TopoDS_Shape aPath = aPathShape->GetValue();
00167     TopoDS_Wire aWire;
00168 
00169     if (aShapeBase.IsNull() || aPath.IsNull())
00170       return 0;
00171 
00172     if ( aPath.ShapeType() == TopAbs_EDGE ) {
00173       TopoDS_Edge anEdge = TopoDS::Edge(aPath);
00174       aWire = BRepBuilderAPI_MakeWire(anEdge); 
00175     }
00176     else if ( aPath.ShapeType() == TopAbs_WIRE)
00177       aWire = TopoDS::Wire(aPath);
00178     else
00179       return 0;
00180 
00181     Handle(GeomFill_TrihedronLaw) TLaw = new GeomFill_CorrectedFrenet();
00182     Handle(GeomFill_CurveAndTrihedron) aLocationLaw = new GeomFill_CurveAndTrihedron( TLaw );
00183     Handle(BRepFill_LocationLaw) aLocation = new BRepFill_Edge3DLaw(aWire, aLocationLaw);
00184 
00185     aLocation->TransformInCompatibleLaw( 0.01 );
00186 
00187     //Calculate a Parameter
00188     Standard_Real aFirstParam1 = 0, aLastParam1 = 0; // Parameters of the First edge
00189     Standard_Real aFirstParam2 = 0, aLastParam2 = 0; // Parameters of the Last edge
00190     aLocation->CurvilinearBounds(aLocation->NbLaw(), aFirstParam2, aLastParam2);
00191 
00192     if ( aLocation->NbLaw() > 1)
00193       aLocation->CurvilinearBounds(1, aFirstParam1, aLastParam1);
00194     else if ( aLocation->NbLaw() == 1 )
00195       aFirstParam1 = aFirstParam2;
00196     else
00197       return 0;
00198 
00199     Standard_Real aParam = (aFirstParam1 + (aLastParam2 - aFirstParam1)*aParameter );
00200 
00201     TopoDS_Shape CopyShape = aShapeBase;
00202     BRepFill_SectionPlacement Place( aLocation, aShapeBase );
00203     TopLoc_Location Loc2(Place.Transformation()), Loc1;
00204     Loc1 = CopyShape.Location();
00205     CopyShape.Location(Loc2.Multiplied(Loc1));
00206 
00207     aLocation->D0( aParam, CopyShape );
00208     aShape = CopyShape;
00209   }
00210   else
00211     return 0;
00212 
00213   if (aShape.IsNull()) return 0;
00214 
00215   aFunction->SetValue(aShape);
00216 
00217   log.SetTouched(Label());
00218 
00219   return 1;
00220 }
00221 
00222 
00223 //=======================================================================
00224 //function :  GEOMImpl_PositionDriver_Type_
00225 //purpose  :
00226 //=======================================================================
00227 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
00228 {
00229 
00230   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00231   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00232   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00233   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00234   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00235   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00236 
00237 
00238   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00239   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
00240                                                          sizeof(GEOMImpl_PositionDriver),
00241                                                          1,
00242                                                          (Standard_Address)_Ancestors,
00243                                                          (Standard_Address)NULL);
00244 
00245   return _aType;
00246 }
00247 
00248 //=======================================================================
00249 //function : DownCast
00250 //purpose  :
00251 //=======================================================================
00252 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00253 {
00254   Handle(GEOMImpl_PositionDriver) _anOtherObject;
00255 
00256   if (!AnObject.IsNull()) {
00257      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
00258        _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
00259      }
00260   }
00261 
00262   return _anOtherObject ;
00263 }