-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// 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.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include <Standard_Stream.hxx>
#include <GEOMImpl_ITranslate.hxx>
#include <GEOMImpl_IMirror.hxx>
+#include <GEOMImpl_IProjection.hxx>
#include <GEOMImpl_IOffset.hxx>
#include <GEOMImpl_IScale.hxx>
#include <GEOMImpl_IRotate.hxx>
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
//Compute the mirror
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
//Compute the mirror
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
//Compute the mirror
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
//Compute the mirror
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
//Compute the mirror
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
//Compute the mirror
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
//Compute the offset
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Offset driver failed");
return NULL;
//Compute the offset
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Offset driver failed");
return NULL;
* ProjectShapeCopy
*/
//=============================================================================
-Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy
- (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget)
+Handle(GEOM_Object)
+GEOMImpl_ITransformOperations::ProjectShapeCopy (Handle(GEOM_Object) theSource,
+ Handle(GEOM_Object) theTarget)
{
SetErrorCode(KO);
Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
+ Handle(GEOM_Object) aCopy;
+
+ TopoDS_Shape aTarget = theTarget->GetValue();
+ if ( aTarget.IsNull() ) return NULL;
+ if ( aTarget.ShapeType() == TopAbs_EDGE ||
+ aTarget.ShapeType() == TopAbs_WIRE )
+ {
+ // a TPythonDump prevents dumping ProjectPointOnWire(),
+ // dump of MakeProjection() is done at the end of this function
+ GEOM::TPythonDump preventDump(aLastFunction, /*append=*/true);
+ Standard_Integer dummy;
+ ProjectPointOnWire( theSource, theTarget, aCopy, dummy );
+ if ( aCopy.IsNull() || !IsDone() )
+ return NULL;
+ }
+ else
+ {
+ //Add a new Projection object
+ aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
+
+ //Add a Projection function
+ Handle(GEOM_Function) aFunction =
+ aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
+
+ GEOMImpl_IMirror aTI (aFunction);
+ aTI.SetPlane(theTarget->GetLastFunction());
+ aTI.SetOriginal(aLastFunction);
+
+ //Compute the Projection
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Projection driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return NULL;
+ }
+ }
+
+ //Make a Python command
+ Handle(GEOM_Function) aFunction = aCopy->GetLastFunction();
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
+ << theSource << ", " << theTarget << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
+//=============================================================================
+/*!
+ * ProjectPointOnWire
+ */
+//=============================================================================
+Standard_Real GEOMImpl_ITransformOperations::ProjectPointOnWire
+ (Handle(GEOM_Object) thePoint,
+ Handle(GEOM_Object) theWire,
+ Handle(GEOM_Object) &thePointOnEdge,
+ Standard_Integer &theEdgeInWireIndex)
+{
+ Standard_Real aResult = -1.;
+
+ SetErrorCode(KO);
+
+ if (thePoint.IsNull() || theWire.IsNull()) {
+ return aResult;
+ }
+
+ Handle(GEOM_Function) aLastFunction = thePoint->GetLastFunction();
+
+ if (aLastFunction.IsNull()) {
+ //There is no function which creates an object to be projected
+ return aResult;
+ }
+
//Add a new Projection object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
+ thePointOnEdge = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
//Add a Projection function
- Handle(GEOM_Function) aFunction =
- aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
+ Handle(GEOM_Function) aFunction = thePointOnEdge->AddFunction
+ (GEOMImpl_ProjectionDriver::GetID(), PROJECTION_ON_WIRE);
//Check if the function is set correctly
- if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
+ if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) {
+ return aResult;
+ }
- GEOMImpl_IMirror aTI (aFunction);
- aTI.SetPlane(theTarget->GetLastFunction());
- aTI.SetOriginal(aLastFunction);
+ GEOMImpl_IProjection aProj (aFunction);
+ aProj.SetPoint(aLastFunction);
+ aProj.SetShape(theWire->GetLastFunction());
//Compute the Projection
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Projection driver failed");
- return NULL;
+ return aResult;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
- return NULL;
+ return aResult;
}
+ aResult = aProj.GetU();
+ theEdgeInWireIndex = aProj.GetIndex();
+
+
//Make a Python command
- GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
- << theSource << ", " << theTarget << ")";
+ GEOM::TPythonDump(aFunction) << "(u, " << thePointOnEdge
+ << ", EdgeInWireIndex) = geompy.MakeProjectionOnWire(" << thePoint
+ << ", " << theWire << ")";
SetErrorCode(OK);
- return aCopy;
-}
+ return aResult;
+}
//=============================================================================
/*!
//Compute the scale
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Scale driver failed");
return NULL;
//Compute the scale
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Scale driver failed");
return NULL;
//Compute the scale
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Scale driver failed");
return NULL;
//Compute the Position
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Position driver failed");
return NULL;
//Compute the position
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Position driver failed");
return NULL;
//Compute the position
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Position driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
//Compute the translation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
// Compute the transformation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Driver failed");
return NULL;