geom/src/GEOMImpl/GEOMImpl_FaceDriver.cxx

171 lines
5.2 KiB
C++
Raw Normal View History

2014-02-18 12:44:41 +06:00
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-13 17:16:39 +05:00
//
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
2014-02-18 12:44:41 +06:00
// version 2.1 of the License, or (at your option) any later version.
2009-02-13 17:16:39 +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.
2009-02-13 17:16:39 +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
//
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_FaceDriver.hxx>
2013-02-12 17:35:16 +06:00
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_IFace.hxx>
#include <GEOMImpl_Types.hxx>
2013-02-12 17:35:16 +06:00
2009-02-13 17:16:39 +05:00
#include <GEOM_Function.hxx>
2013-02-12 17:35:16 +06:00
#include <GEOMUtils.hxx>
2009-02-13 17:16:39 +05:00
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRep_Tool.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
#include <StdFail_NotDone.hxx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& GEOMImpl_FaceDriver::GetID()
{
static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
return aFaceDriver;
}
//=======================================================================
//function : GEOMImpl_FaceDriver
//purpose :
//=======================================================================
GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
{
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
GEOMImpl_IFace aFI (aFunction);
Standard_Integer aType = aFunction->GetType();
TopoDS_Shape aShape;
if (aType == FACE_OBJ_H_W) {
Handle(GEOM_Function) aRefFunct = aFI.GetRef1();
TopoDS_Shape aRefShape = aRefFunct->GetValue();
if (aRefShape.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge anEdge = TopoDS::Edge(aRefShape);
double aH = aFI.GetH() / 2.0;
double aW = aFI.GetW() / 2.0;
TopoDS_Vertex V1, V2;
TopExp::Vertices(anEdge, V1, V2, Standard_True);
gp_Pnt aP (BRep_Tool::Pnt(V1));
gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
gp_Pln aPlane (aP, aV);
aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
} else if (aRefShape.ShapeType() == TopAbs_FACE) {
double aH = aFI.GetH() / 2.0;
double aW = aFI.GetW() / 2.0;
2013-02-12 17:35:16 +06:00
gp_Ax3 anAx = GEOMUtils::GetPosition(aRefShape);
2009-02-13 17:16:39 +05:00
gp_Pln aPln (anAx);
aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
}
}
else if (aType == FACE_H_W) {
double aH = aFI.GetH() / 2.0;
double aW = aFI.GetW() / 2.0;
TopoDS_Vertex V1, V2;
int anOrient = aFI.GetOrientation();
gp_Pnt aP = gp::Origin();
gp_Vec aV;
if (anOrient == 1)
aV = gp::DZ();
else if (anOrient == 2)
aV = gp::DX();
else if (anOrient == 3)
aV = gp::DY();
gp_Pln aPlane (aP, aV);
aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
}
else {
}
if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape);
log.SetTouched(Label());
return 1;
}
//================================================================================
/*!
* \brief Returns a name of creation operation and names and values of creation parameters
*/
//================================================================================
bool GEOMImpl_FaceDriver::
GetCreationInformation(std::string& theOperationName,
std::vector<GEOM_Param>& theParams)
2009-02-13 17:16:39 +05:00
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
2009-02-13 17:16:39 +05:00
GEOMImpl_IFace aCI( function );
Standard_Integer aType = function->GetType();
2009-02-13 17:16:39 +05:00
theOperationName = "RECTANGLE";
2009-02-13 17:16:39 +05:00
switch ( aType ) {
case FACE_OBJ_H_W:
{
Handle(GEOM_Function) aRefFunct = aCI.GetRef1();
TopoDS_Shape aRefShape = aRefFunct->GetValue();
if (aRefShape.ShapeType() == TopAbs_EDGE)
AddParam( theParams, "Edge", aRefFunct );
else
AddParam( theParams, "Face", aRefFunct );
AddParam( theParams, "Height", aCI.GetH() );
AddParam( theParams, "Width", aCI.GetW() );
break;
2009-02-13 17:16:39 +05:00
}
case FACE_H_W:
AddParam( theParams, "Height", aCI.GetH() );
AddParam( theParams, "Width", aCI.GetW() );
AddParam( theParams, "Orientation", aCI.GetOrientation() );
break;
default:
return false;
}
return true;
2009-02-13 17:16:39 +05:00
}
IMPLEMENT_STANDARD_HANDLE (GEOMImpl_FaceDriver,GEOM_BaseDriver);
IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_FaceDriver,GEOM_BaseDriver);