1 // Copyright (C) 2014-2015 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "CANRECPluginImpl_IOperations.hxx"
21 #include "CANRECPluginImpl_Driver.hxx"
22 #include "CANRECPluginImpl_ICanRec.hxx"
23 #include "CANRECPluginImpl_Types.hxx"
25 #include <GEOM_PythonDump.hxx>
27 #include <utilities.h>
29 #include <Standard_ErrorHandler.hxx>
31 CANRECPluginImpl_IOperations::CANRECPluginImpl_IOperations( GEOM_Engine* theEngine, int theDocID)
32 : GEOM_IOperations( theEngine, theDocID )
34 MESSAGE( "CANRECPluginImpl_IOperations::CANRECPluginImpl_IOperations()" );
37 CANRECPluginImpl_IOperations::~CANRECPluginImpl_IOperations()
39 MESSAGE( "CANRECPluginImpl_IOperations::~CANRECPluginImpl_IOperations()" );
42 //=============================================================================
44 * Create a canonical recognition for the object
45 * \param theMergeSurf set merging surfaces
46 * \param theMergeCurves set merging curves
47 * \param theTolerance set tolerance
48 * \param theObject is initial object
49 * \return New GEOM_Object, containing the created shape.
51 //=============================================================================
53 CANRECPluginImpl_IOperations::MakeCanonicalRecognition ( Handle(GEOM_Object) theObject,
60 if ( theObject.IsNull() ) return NULL;
63 Handle(GEOM_Object) aShape = GetEngine()->AddObject( GetDocID(), GEOM_CANONICALRECOGNITION );
65 // Add a new shape function with parameters
66 Handle(GEOM_Function) aFunction = aShape->AddFunction( CANRECPluginImpl_Driver::GetID(), CANONICALRECOGNITION_OBJ );
67 if ( aFunction.IsNull() ) return NULL;
69 // Check if the function is set correctly
70 if ( aFunction->GetDriverGUID() != CANRECPluginImpl_Driver::GetID() ) return NULL;
72 Handle(GEOM_Function) aRefFunction = theObject->GetLastFunction();
74 if ( aRefFunction.IsNull() ) return NULL;
76 CANRECPluginImpl_ICanRec aData( aFunction );
77 aData.SetNeedMergeSurf( theMergeSurf );
78 aData.SetNeedMergeCurves( theMergeCurves );
79 aData.SetTolerance( theTolerance );
80 aData.SetObject( aRefFunction );
82 // Compute the resulting value
85 if ( !GetSolver()->ComputeFunction( aFunction ) ) {
86 SetErrorCode( "Canonical Recognition driver failed" );
90 catch ( Standard_Failure ) {
91 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
92 SetErrorCode( aFail->GetMessageString() );
96 // Make a Python command
97 GEOM::TPythonDump(aFunction) << aShape << " = " << "geompy.MakeCanonicalRecognition(" <<
98 theObject << ", " << theMergeSurf << ", " << theMergeCurves << ", " << theTolerance << ")";