geom/src/GEOMImpl/GEOMImpl_PositionDriver.cxx

266 lines
8.4 KiB
C++
Raw Normal View History

2019-02-14 13:09:13 +03:00
// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
//
2012-08-09 07:58:02 +00: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 07:58:02 +00: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
2014-02-18 10:44:41 +04:00
// version 2.1 of the License, or (at your option) any later version.
2005-12-05 16:23:52 +00:00
//
2012-08-09 07:58:02 +00: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 16:23:52 +00:00
//
2012-08-09 07:58:02 +00: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 12:16:39 +00:00
//
2012-08-09 07:58:02 +00:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2013-04-01 12:25:01 +00:00
//
2012-08-09 07:58:02 +00:00
2005-08-11 04:43:57 +00:00
#include <GEOMImpl_PositionDriver.hxx>
2013-02-12 11:35:16 +00:00
2005-08-11 04:43:57 +00:00
#include <GEOMImpl_IPosition.hxx>
#include <GEOMImpl_Types.hxx>
2013-02-12 11:35:16 +00:00
2005-08-11 04:43:57 +00:00
#include <GEOM_Function.hxx>
2004-12-01 10:39:14 +00:00
2013-02-12 11:35:16 +00:00
#include <GEOMUtils.hxx>
// OCCT Includes
2004-12-01 10:39:14 +00:00
#include <BRepBuilderAPI_Transform.hxx>
2009-02-13 12:16:39 +00:00
#include <ShHealOper_EdgeDivide.hxx>
2004-12-01 10:39:14 +00:00
#include <BRep_Tool.hxx>
2009-02-13 12:16:39 +00:00
#include <BRepTools.hxx>
2012-08-09 07:58:02 +00:00
#include <BRepFill_LocationLaw.hxx>
#include <BRepFill_Edge3DLaw.hxx>
#include <BRepFill_SectionPlacement.hxx>
2009-02-13 12:16:39 +00:00
#include <BRepTools_WireExplorer.hxx>
2012-08-09 07:58:02 +00:00
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
2004-12-01 10:39:14 +00:00
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
2009-02-13 12:16:39 +00:00
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
2004-12-01 10:39:14 +00:00
#include <TopAbs.hxx>
#include <TopExp.hxx>
2009-02-13 12:16:39 +00:00
#include <TopExp_Explorer.hxx>
2004-12-01 10:39:14 +00:00
#include <gp_Pln.hxx>
#include <Geom_Plane.hxx>
2009-02-13 12:16:39 +00:00
#include <Geom_Curve.hxx>
2004-12-01 10:39:14 +00:00
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
2009-02-13 12:16:39 +00:00
#include <ShapeAnalysis_Edge.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <BRepGProp.hxx>
#include <ShapeFix_Wire.hxx>
2004-12-01 10:39:14 +00:00
2012-08-09 07:58:02 +00:00
#include <GeomFill_TrihedronLaw.hxx>
#include <GeomFill_CurveAndTrihedron.hxx>
#include <GeomFill_CorrectedFrenet.hxx>
2004-12-01 10:39:14 +00:00
#include <Precision.hxx>
#include <gp_Pnt.hxx>
2009-02-13 12:16:39 +00:00
#include <gp_Vec.hxx>
#include <TopExp.hxx>
2004-12-01 10:39:14 +00:00
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
2004-12-01 10:39:14 +00:00
const Standard_GUID& GEOMImpl_PositionDriver::GetID()
{
static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
return aPositionDriver;
2004-12-01 10:39:14 +00:00
}
//=======================================================================
//function : GEOMImpl_PositionDriver
//purpose :
2004-12-01 10:39:14 +00:00
//=======================================================================
GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
2004-12-01 10:39:14 +00:00
{
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOMImpl_PositionDriver::Execute(Handle(TFunction_Logbook)& log) const
2004-12-01 10:39:14 +00:00
{
if (Label().IsNull()) return 0;
2004-12-01 10:39:14 +00: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 07:58:02 +00:00
aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
2004-12-01 10:39:14 +00:00
return 0;
gp_Trsf aTrsf;
gp_Ax3 aStartAx3, aDestAx3;
// End LCS
2013-02-12 11:35:16 +00:00
aDestAx3 = GEOMUtils::GetPosition(aShapeEndLCS);
// Start LCS
2013-02-12 11:35:16 +00: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 11:35:16 +00:00
aDestAx3 = GEOMUtils::GetPosition(aShapeEndLCS);
// Set transformation
aTrsf.SetDisplacement(aStartAx3, aDestAx3);
// Perform transformation
2004-12-01 10:39:14 +00:00
BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
aShape = aBRepTrsf.Shape();
}
2009-02-13 12:16:39 +00:00
else if (aType == POSITION_ALONG_PATH) {
Handle(GEOM_Function) aRefShape = aCI.GetShape();
Handle(GEOM_Function) aPathShape = aCI.GetPath();
2012-08-09 07:58:02 +00:00
Standard_Real aParameter = aCI.GetDistance();
2009-02-13 12:16:39 +00:00
bool aReversed = aCI.GetReverse();
2012-08-09 07:58:02 +00:00
if (aReversed)
aParameter = 1 - aParameter;
2009-02-13 12:16:39 +00:00
TopoDS_Shape aShapeBase = aRefShape->GetValue();
TopoDS_Shape aPath = aPathShape->GetValue();
2012-08-09 07:58:02 +00:00
TopoDS_Wire aWire;
2009-02-13 12:16:39 +00:00
if (aShapeBase.IsNull() || aPath.IsNull())
return 0;
2012-08-09 07:58:02 +00:00
if ( aPath.ShapeType() == TopAbs_EDGE ) {
TopoDS_Edge anEdge = TopoDS::Edge(aPath);
aWire = BRepBuilderAPI_MakeWire(anEdge);
2009-02-13 12:16:39 +00:00
}
2012-08-09 07:58:02 +00:00
else if ( aPath.ShapeType() == TopAbs_WIRE)
aWire = TopoDS::Wire(aPath);
else
return 0;
2009-02-13 12:16:39 +00:00
2012-08-09 07:58:02 +00: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 12:16:39 +00:00
2012-08-09 07:58:02 +00:00
aLocation->TransformInCompatibleLaw( 0.01 );
2009-02-13 12:16:39 +00:00
2012-08-09 07:58:02 +00: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 12:16:39 +00:00
}
2004-12-01 10:39:14 +00:00
else
return 0;
if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape);
2016-02-24 16:45:13 +03:00
log->SetTouched(Label());
2004-12-01 10:39:14 +00:00
return 1;
2004-12-01 10:39:14 +00: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 10:39:14 +00: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 10:39:14 +00:00
}
return true;
2004-12-01 10:39:14 +00:00
}
IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PositionDriver,GEOM_BaseDriver);