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 * \param theStat is the statistics. A set of integers. For details please
50 * see CANRECPlugin.idl
51 * \return New GEOM_Object, containing the created shape.
53 //=============================================================================
55 CANRECPluginImpl_IOperations::MakeCanonicalRecognition
56 (Handle(GEOM_Object) theObject,
60 Handle_TColStd_HSequenceOfInteger &theStat)
64 if (theStat.IsNull()) {
65 theStat = new TColStd_HSequenceOfInteger;
70 if ( theObject.IsNull() ) return NULL;
73 Handle(GEOM_Object) aShape = GetEngine()->AddObject( GetDocID(), GEOM_CANONICALRECOGNITION );
75 // Add a new shape function with parameters
76 Handle(GEOM_Function) aFunction = aShape->AddFunction( CANRECPluginImpl_Driver::GetID(), CANONICALRECOGNITION_OBJ );
77 if ( aFunction.IsNull() ) return NULL;
79 // Check if the function is set correctly
80 if ( aFunction->GetDriverGUID() != CANRECPluginImpl_Driver::GetID() ) return NULL;
82 Handle(GEOM_Function) aRefFunction = theObject->GetLastFunction();
84 if ( aRefFunction.IsNull() ) return NULL;
86 CANRECPluginImpl_ICanRec aData( aFunction );
87 aData.SetNeedMergeSurf( theMergeSurf );
88 aData.SetNeedMergeCurves( theMergeCurves );
89 aData.SetTolerance( theTolerance );
90 aData.SetObject( aRefFunction );
92 // Compute the resulting value
95 if ( !GetSolver()->ComputeFunction( aFunction ) ) {
96 SetErrorCode( "Canonical Recognition driver failed" );
100 catch ( Standard_Failure ) {
101 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
102 SetErrorCode( aFail->GetMessageString() );
106 Handle(TColStd_HArray1OfInteger) anArray = aData.GetStatistics();
108 if (anArray.IsNull() == Standard_False) {
109 Standard_Integer i = anArray->Lower();
110 const Standard_Integer iUp = anArray->Upper();
112 for (; i <= iUp; ++i) {
113 theStat->Append(anArray->Value(i));
117 // Make a Python command
118 GEOM::TPythonDump(aFunction) << aShape << " = " << "geompy.MakeCanonicalRecognition(" <<
119 theObject << ", " << theMergeSurf << ", " << theMergeCurves << ", " << theTolerance << ")";
126 //=============================================================================
128 * \brief Get the number of canonical faces in the shape.
130 * \param theObject the input object (solid, compound, compsolid).
132 * \return the number of canonical faces in the object.
134 //=============================================================================
135 Standard_Integer CANRECPluginImpl_IOperations::GetNbCanonicalFaces
136 (const Handle(GEOM_Object) &theObject)
140 TopoDS_Shape aShape = theObject->GetValue();
142 if (aShape.IsNull()) {
146 const Standard_Integer aResult =
147 CANRECPluginImpl_Driver::GetNbCanonicalFaces(aShape);