geom/src/GEOMImpl/GEOMImpl_PositionDriver.cxx

267 lines
8.4 KiB
C++
Raw Normal View History

2013-04-01 18:25:01 +06:00
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
2012-08-09 13:58:02 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
2005-12-05 21:23:52 +05:00
//
2012-08-09 13:58:02 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2005-12-05 21:23:52 +05:00
//
2012-08-09 13:58:02 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2013-04-01 18:25:01 +06:00
//
2012-08-09 13:58:02 +06:00
2005-08-11 10:43:57 +06:00
#include <GEOMImpl_PositionDriver.hxx>
2013-02-12 17:35:16 +06:00
2005-08-11 10:43:57 +06:00
#include <GEOMImpl_IPosition.hxx>
#include <GEOMImpl_Types.hxx>
2013-02-12 17:35:16 +06:00
2005-08-11 10:43:57 +06:00
#include <GEOM_Function.hxx>
2004-12-01 15:39:14 +05:00
2013-02-12 17:35:16 +06:00
#include <GEOMUtils.hxx>
// OCCT Includes
2004-12-01 15:39:14 +05:00
#include <BRepBuilderAPI_Transform.hxx>
2009-02-13 17:16:39 +05:00
#include <ShHealOper_EdgeDivide.hxx>
2004-12-01 15:39:14 +05:00
#include <BRep_Tool.hxx>
2009-02-13 17:16:39 +05:00
#include <BRepTools.hxx>
2012-08-09 13:58:02 +06:00
#include <BRepFill_LocationLaw.hxx>
#include <BRepFill_Edge3DLaw.hxx>
#include <BRepFill_SectionPlacement.hxx>
2009-02-13 17:16:39 +05:00
#include <BRepTools_WireExplorer.hxx>
2012-08-09 13:58:02 +06:00
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
2004-12-01 15:39:14 +05:00
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
2009-02-13 17:16:39 +05:00
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
2004-12-01 15:39:14 +05:00
#include <TopAbs.hxx>
#include <TopExp.hxx>
2009-02-13 17:16:39 +05:00
#include <TopExp_Explorer.hxx>
2004-12-01 15:39:14 +05:00
#include <gp_Pln.hxx>
#include <Geom_Plane.hxx>
2009-02-13 17:16:39 +05:00
#include <Geom_Curve.hxx>
2004-12-01 15:39:14 +05:00
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
2009-02-13 17:16:39 +05:00
#include <ShapeAnalysis_Edge.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <BRepGProp.hxx>
#include <ShapeFix_Wire.hxx>
2004-12-01 15:39:14 +05:00
2012-08-09 13:58:02 +06:00
#include <GeomFill_TrihedronLaw.hxx>
#include <GeomFill_CurveAndTrihedron.hxx>
#include <GeomFill_CorrectedFrenet.hxx>
2004-12-01 15:39:14 +05:00
#include <Precision.hxx>
#include <gp_Pnt.hxx>
2009-02-13 17:16:39 +05:00
#include <gp_Vec.hxx>
#include <TopExp.hxx>
2004-12-01 15:39:14 +05:00
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
2004-12-01 15:39:14 +05:00
const Standard_GUID& GEOMImpl_PositionDriver::GetID()
{
static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
return aPositionDriver;
2004-12-01 15:39:14 +05:00
}
//=======================================================================
//function : GEOMImpl_PositionDriver
//purpose :
2004-12-01 15:39:14 +05:00
//=======================================================================
GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
2004-12-01 15:39:14 +05:00
{
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
2004-12-01 15:39:14 +05:00
Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
2004-12-01 15:39:14 +05:00
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
GEOMImpl_IPosition aCI (aFunction);
Standard_Integer aType = aFunction->GetType();
TopoDS_Shape aShape;
if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
Handle(GEOM_Function) aRefShape = aCI.GetShape();
Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
TopoDS_Shape aShapeBase = aRefShape->GetValue();
TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
2012-08-09 13:58:02 +06:00
aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
2004-12-01 15:39:14 +05:00
return 0;
gp_Trsf aTrsf;
gp_Ax3 aStartAx3, aDestAx3;
// End LCS
2013-02-12 17:35:16 +06:00
aDestAx3 = GEOMUtils::GetPosition(aShapeEndLCS);
// Start LCS
2013-02-12 17:35:16 +06:00
aStartAx3 = GEOMUtils::GetPosition(aShapeStartLCS);
// Set transformation
aTrsf.SetDisplacement(aStartAx3, aDestAx3);
// Perform transformation
BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
aShape = aBRepTrsf.Shape();
}
else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
Handle(GEOM_Function) aRefShape = aCI.GetShape();
Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
TopoDS_Shape aShapeBase = aRefShape->GetValue();
TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
aShapeEndLCS.ShapeType() != TopAbs_FACE)
return 0;
gp_Trsf aTrsf;
gp_Ax3 aStartAx3, aDestAx3;
// End LCS
2013-02-12 17:35:16 +06:00
aDestAx3 = GEOMUtils::GetPosition(aShapeEndLCS);
// Set transformation
aTrsf.SetDisplacement(aStartAx3, aDestAx3);
// Perform transformation
2004-12-01 15:39:14 +05:00
BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
aShape = aBRepTrsf.Shape();
}
2009-02-13 17:16:39 +05:00
else if (aType == POSITION_ALONG_PATH) {
Handle(GEOM_Function) aRefShape = aCI.GetShape();
Handle(GEOM_Function) aPathShape = aCI.GetPath();
2012-08-09 13:58:02 +06:00
Standard_Real aParameter = aCI.GetDistance();
2009-02-13 17:16:39 +05:00
bool aReversed = aCI.GetReverse();
2012-08-09 13:58:02 +06:00
if (aReversed)
aParameter = 1 - aParameter;
2009-02-13 17:16:39 +05:00
TopoDS_Shape aShapeBase = aRefShape->GetValue();
TopoDS_Shape aPath = aPathShape->GetValue();
2012-08-09 13:58:02 +06:00
TopoDS_Wire aWire;
2009-02-13 17:16:39 +05:00
if (aShapeBase.IsNull() || aPath.IsNull())
return 0;
2012-08-09 13:58:02 +06:00
if ( aPath.ShapeType() == TopAbs_EDGE ) {
TopoDS_Edge anEdge = TopoDS::Edge(aPath);
aWire = BRepBuilderAPI_MakeWire(anEdge);
2009-02-13 17:16:39 +05:00
}
2012-08-09 13:58:02 +06:00
else if ( aPath.ShapeType() == TopAbs_WIRE)
aWire = TopoDS::Wire(aPath);
else
return 0;
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
Handle(GeomFill_TrihedronLaw) TLaw = new GeomFill_CorrectedFrenet();
Handle(GeomFill_CurveAndTrihedron) aLocationLaw = new GeomFill_CurveAndTrihedron( TLaw );
Handle(BRepFill_LocationLaw) aLocation = new BRepFill_Edge3DLaw(aWire, aLocationLaw);
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
aLocation->TransformInCompatibleLaw( 0.01 );
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
//Calculate a Parameter
Standard_Real aFirstParam1 = 0, aLastParam1 = 0; // Parameters of the First edge
Standard_Real aFirstParam2 = 0, aLastParam2 = 0; // Parameters of the Last edge
aLocation->CurvilinearBounds(aLocation->NbLaw(), aFirstParam2, aLastParam2);
if ( aLocation->NbLaw() > 1)
aLocation->CurvilinearBounds(1, aFirstParam1, aLastParam1);
else if ( aLocation->NbLaw() == 1 )
aFirstParam1 = aFirstParam2;
else
return 0;
Standard_Real aParam = (aFirstParam1 + (aLastParam2 - aFirstParam1)*aParameter );
TopoDS_Shape CopyShape = aShapeBase;
BRepFill_SectionPlacement Place( aLocation, aShapeBase );
TopLoc_Location Loc2(Place.Transformation()), Loc1;
Loc1 = CopyShape.Location();
CopyShape.Location(Loc2.Multiplied(Loc1));
aLocation->D0( aParam, CopyShape );
aShape = CopyShape;
2009-02-13 17:16:39 +05:00
}
2004-12-01 15:39:14 +05:00
else
return 0;
if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape);
log.SetTouched(Label());
2004-12-01 15:39:14 +05:00
return 1;
2004-12-01 15:39:14 +05:00
}
//================================================================================
/*!
* \brief Returns a name of creation operation and names and values of creation parameters
*/
//================================================================================
bool GEOMImpl_PositionDriver::
GetCreationInformation(std::string& theOperationName,
std::vector<GEOM_Param>& theParams)
2004-12-01 15:39:14 +05:00
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
GEOMImpl_IPosition aCI( function );
Standard_Integer aType = function->GetType();
theOperationName = "MODIFY_LOCATION";
switch ( aType ) {
case POSITION_SHAPE:
case POSITION_SHAPE_COPY:
AddParam( theParams, "Object", aCI.GetShape() );
AddParam( theParams, "Start LCS", aCI.GetStartLCS() );
AddParam( theParams, "End LCS", aCI.GetEndLCS() );
break;
case POSITION_SHAPE_FROM_GLOBAL:
case POSITION_SHAPE_FROM_GLOBAL_COPY:
AddParam( theParams, "Object", aCI.GetShape() );
AddParam( theParams, "End LCS", aCI.GetEndLCS() );
break;
case POSITION_ALONG_PATH:
AddParam( theParams, "Object", aCI.GetShape() );
AddParam( theParams, "Path", aCI.GetPath() );
AddParam( theParams, "Distance", aCI.GetDistance() );
AddParam( theParams, "Reverse Direction", aCI.GetReverse() );
break;
default:
return false;
2004-12-01 15:39:14 +05:00
}
return true;
2004-12-01 15:39:14 +05:00
}
IMPLEMENT_STANDARD_HANDLE (GEOMImpl_PositionDriver,GEOM_BaseDriver);
IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PositionDriver,GEOM_BaseDriver);