1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D
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
21 // File : HexoticPlugin_Hexotic.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
25 #include "HexoticPlugin_Hexotic.hxx"
26 #include "HexoticPlugin_Hypothesis.hxx"
27 #include "MG_Hexotic_API.hxx"
29 #include "utilities.h"
42 #include <SMESHDS_GroupBase.hxx>
43 #include <SMESHDS_Mesh.hxx>
44 #include <SMESH_ComputeError.hxx>
45 #include <SMESH_File.hxx>
46 #include <SMESH_Gen.hxx>
47 #include <SMESH_HypoFilter.hxx>
48 #include <SMESH_MesherHelper.hxx>
49 #include <SMESH_subMesh.hxx>
50 #include <SMESH_MeshEditor.hxx>
51 #include <SMESH_ControlPnt.hxx>
56 #include <Standard_ProgramError.hxx>
58 #include <BRepBndLib.hxx>
59 #include <BRepClass3d_SolidClassifier.hxx>
60 #include <BRep_Tool.hxx>
61 #include <Bnd_Box.hxx>
62 #include <OSD_File.hxx>
63 #include <Precision.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_MapOfShape.hxx>
67 #include <TopoDS_Vertex.hxx>
70 #include <Basics_Utils.hxx>
71 #include <GEOMImpl_Types.hxx>
72 #include <GEOM_wrap.hxx>
74 #define GMFVERSION GmfDouble
75 #define GMFDIMENSION 3
77 using SMESHUtils::ControlPnt;
79 static void removeFile( const TCollection_AsciiString& fileName )
82 OSD_File( fileName ).Remove();
84 catch ( Standard_ProgramError& ) {
85 MESSAGE("Can't remove file: " << fileName.ToCString() << " ; file does not exist or permission denied");
89 //=============================================================================
93 //=============================================================================
95 HexoticPlugin_Hexotic::HexoticPlugin_Hexotic(int hypId, SMESH_Gen* gen)
96 : SMESH_3D_Algo(hypId, gen)
99 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
100 _onlyUnaryInput = false;
101 _requireShape = false;
104 _hexoticFilesKept=false;
105 _compatibleHypothesis.push_back( HexoticPlugin_Hypothesis::GetHypType() );
106 #ifdef WITH_BLSURFPLUGIN
109 _computeCanceled = false;
113 //=============================================================================
117 //=============================================================================
119 HexoticPlugin_Hexotic::~HexoticPlugin_Hexotic()
124 #ifdef WITH_BLSURFPLUGIN
125 bool HexoticPlugin_Hexotic::CheckBLSURFHypothesis( SMESH_Mesh& aMesh,
126 const TopoDS_Shape& aShape )
130 std::list<const SMESHDS_Hypothesis*>::const_iterator itl;
131 const SMESHDS_Hypothesis* theHyp;
133 // If a BLSURF hypothesis is applied, get it
134 SMESH_HypoFilter blsurfFilter;
135 blsurfFilter.Init( blsurfFilter.HasName( BLSURFPlugin_Hypothesis::GetHypType(true) ));
136 blsurfFilter.Or ( blsurfFilter.HasName( BLSURFPlugin_Hypothesis::GetHypType(false)));
137 std::list<const SMESHDS_Hypothesis *> appliedHyps;
138 aMesh.GetHypotheses( aShape, blsurfFilter, appliedHyps, false );
140 if ( appliedHyps.size() > 0 ) {
141 itl = appliedHyps.begin();
142 theHyp = (*itl); // use only the first hypothesis
143 std::string hypName = theHyp->GetName();
144 if (hypName == BLSURFPlugin_Hypothesis::GetHypType(true) ||
145 hypName == BLSURFPlugin_Hypothesis::GetHypType(false) )
147 _blsurfHypo = static_cast<const BLSURFPlugin_Hypothesis*> (theHyp);
156 //=============================================================================
160 //=============================================================================
162 bool HexoticPlugin_Hexotic::CheckHypothesis( SMESH_Mesh& aMesh,
163 const TopoDS_Shape& aShape,
164 SMESH_Hypothesis::Hypothesis_Status& aStatus )
168 std::list<const SMESHDS_Hypothesis*>::const_iterator itl;
169 const SMESHDS_Hypothesis* theHyp;
171 const std::list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape, false);
172 int nbHyp = hyps.size();
174 // retrieve BLSURF hypothesis if no hexotic hypothesis has been set
175 #ifdef WITH_BLSURFPLUGIN
176 CheckBLSURFHypothesis(aMesh, aShape);
178 aStatus = SMESH_Hypothesis::HYP_OK;
179 return true; // can work with no hypothesis
183 theHyp = (*itl); // use only the first hypothesis
185 std::string hypName = theHyp->GetName();
186 if (hypName == HexoticPlugin_Hypothesis::GetHypType() ) {
187 _hypothesis = static_cast<const HexoticPlugin_Hypothesis*> (theHyp);
189 aStatus = SMESH_Hypothesis::HYP_OK;
192 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
194 #ifdef WITH_BLSURFPLUGIN
195 CheckBLSURFHypothesis(aMesh, aShape);
198 return aStatus == SMESH_Hypothesis::HYP_OK;
201 //=======================================================================
202 //function : findShape
204 //=======================================================================
206 static TopoDS_Shape findShape(SMDS_MeshNode** t_Node,
208 const TopoDS_Shape* t_Shape,
213 int iShape, nbNode = 8;
215 for ( int i=0; i<3; i++ ) {
217 for ( int j=0; j<nbNode; j++ ) {
218 if ( i == 0) pntCoor[i] += t_Node[j]->X();
219 if ( i == 1) pntCoor[i] += t_Node[j]->Y();
220 if ( i == 2) pntCoor[i] += t_Node[j]->Z();
222 pntCoor[i] /= nbNode;
224 gp_Pnt aPnt(pntCoor[0], pntCoor[1], pntCoor[2]);
226 if ( aShape.IsNull() ) aShape = t_Shape[0];
227 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
228 if ( !(SC.State() == TopAbs_IN) ) {
230 for (iShape = 0; iShape < nShape && aShape.IsNull(); iShape++) {
231 if ( !( pntCoor[0] < t_Box[iShape][0] || t_Box[iShape][1] < pntCoor[0] ||
232 pntCoor[1] < t_Box[iShape][2] || t_Box[iShape][3] < pntCoor[1] ||
233 pntCoor[2] < t_Box[iShape][4] || t_Box[iShape][5] < pntCoor[2]) ) {
234 BRepClass3d_SolidClassifier SC (t_Shape[iShape], aPnt, Precision::Confusion());
235 if (SC.State() == TopAbs_IN)
236 aShape = t_Shape[iShape];
243 //=======================================================================
244 //function : getNbShape
246 //=======================================================================
248 static int getNbShape(MG_Hexotic_API* hexaOutput, int iMesh, GmfKwdCod what, int defaultValue=0)
250 int number = hexaOutput->GmfStatKwd( iMesh, what );
253 number = ( number + defaultValue + std::abs(number - defaultValue) ) / 2;
257 number = defaultValue;
262 //=======================================================================
263 //function : countShape
265 //=======================================================================
267 static int countShape( SMESH_Mesh* mesh, TopAbs_ShapeEnum shape )
269 if ( !mesh->HasShapeToMesh() )
271 TopExp_Explorer expShape ( mesh->GetShapeToMesh(), shape );
272 TopTools_MapOfShape mapShape;
274 for ( ; expShape.More(); expShape.Next() ) {
275 if (mapShape.Add(expShape.Current())) {
282 //=======================================================================
283 //function : getShape
285 //=======================================================================
287 template < class Mesh, class Shape, class Tab >
288 void getShape(Mesh* mesh, Shape shape, Tab *t_Shape)
290 TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
291 TopTools_MapOfShape mapShape;
292 for ( int i=0; expShape.More(); expShape.Next() ) {
293 if (mapShape.Add(expShape.Current())) {
294 t_Shape[i] = expShape.Current();
301 //=======================================================================
302 //function : printWarning
304 //=======================================================================
306 static void printWarning(const int nbExpected, std::string aString, const int nbFound) {
307 std::cout << std::endl;
308 std::cout << "WARNING : " << nbExpected << " " << aString << " expected, MG-Hexa has found " << nbFound << std::endl;
309 std::cout << "=======" << std::endl;
310 std::cout << std::endl;
314 //=======================================================================
315 //function : removeHexoticFiles
317 //=======================================================================
319 static void removeHexoticFiles(TCollection_AsciiString file_In, TCollection_AsciiString file_Out)
321 removeFile( file_In );
322 removeFile( file_Out );
325 //=======================================================================
326 //function : splitQuads
327 //purpose : splits all quadrangles into triangles
328 //=======================================================================
330 static void splitQuads(SMESH_Mesh& aMesh)
332 SMESH_MeshEditor spliter( &aMesh );
334 TIDSortedElemSet elems;
335 SMDS_ElemIteratorPtr eIt = aMesh.GetMeshDS()->elementsIterator();
337 elems.insert( elems.end(), eIt->next() );
339 spliter.QuadToTri ( elems, /*the13Diag=*/true);
342 //=======================================================================
343 //function : writeInput
344 //purpose : pass a mesh to input of MG-Hexa
345 //=======================================================================
347 static void writeInput(MG_Hexotic_API* theHexaInput,
349 const SMESHDS_Mesh* theMeshDS)
351 int meshID = theHexaInput->GmfOpenMesh( theFile, GmfWrite, GMFVERSION, GMFDIMENSION);
355 smIdType nbNodes = theMeshDS->NbNodes();
356 theHexaInput->GmfSetKwd( meshID, GmfVertices, nbNodes );
357 std::map< const SMDS_MeshNode*, int, TIDCompare > node2IdMap;
358 SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
360 while ( nodeIt->more() )
362 n.Set( nodeIt->next() );
363 theHexaInput->GmfSetLin( meshID, GmfVertices, n.X(), n.Y(), n.Z(), n._node->getshapeId() );
364 node2IdMap.insert( node2IdMap.end(), std::make_pair( n._node, ++iN ));
368 SMDS_ElemIteratorPtr elemIt = theMeshDS->elementsIterator( SMDSAbs_Edge );
369 if ( elemIt->more() )
371 smIdType nbEdges = theMeshDS->GetMeshInfo().NbElements( SMDSAbs_Edge );
372 theHexaInput->GmfSetKwd(meshID, GmfEdges, nbEdges );
373 for ( int gmfID = 1; elemIt->more(); ++gmfID )
375 const SMDS_MeshElement* edge = elemIt->next();
376 theHexaInput->GmfSetLin(meshID, GmfEdges,
377 node2IdMap[ edge->GetNode( 0 )],
378 node2IdMap[ edge->GetNode( 1 )],
379 edge->getshapeId() );
384 elemIt = theMeshDS->elementGeomIterator( SMDSGeom_TRIANGLE );
385 if ( elemIt->more() )
387 smIdType nbTria = theMeshDS->GetMeshInfo().NbElements( SMDSGeom_TRIANGLE );
388 theHexaInput->GmfSetKwd(meshID, GmfTriangles, nbTria );
389 for ( int gmfID = 1; elemIt->more(); ++gmfID )
391 const SMDS_MeshElement* tria = elemIt->next();
392 theHexaInput->GmfSetLin(meshID, GmfTriangles,
393 node2IdMap[ tria->GetNode( 0 )],
394 node2IdMap[ tria->GetNode( 1 )],
395 node2IdMap[ tria->GetNode( 2 )],
396 tria->getshapeId() );
399 theHexaInput->GmfCloseMesh( meshID );
402 //=======================================================================
403 //function : readResult
404 //purpose : Read GMF file in case of a mesh with geometry
405 //=======================================================================
407 static bool readResult(MG_Hexotic_API* theHexaOutput,
409 HexoticPlugin_Hexotic*theAlgo,
410 SMESH_MesherHelper* theHelper,
411 const int nbShape = 0,
412 const TopoDS_Shape* tabShape = 0,
415 SMESH_Mesh* theMesh = theHelper->GetMesh();
416 SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS();
418 // ---------------------------------
419 // Read generated elements and nodes
420 // ---------------------------------
423 TopoDS_Vertex aVertex;
425 int shapeID, hexoticShapeID;
426 const int IdShapeRef = 2;
427 std::vector< int > tabID;
428 double epsilon = Precision::Confusion();
429 std::map <std::string,int> mapField;
430 std::vector< SMDS_MeshNode*> HexoticNode;
431 std::vector< TopoDS_Shape > tabCorner;
433 const int nbDomains = countShape( theMesh, TopAbs_SHELL );
434 const int holeID = -1;
438 tabID.resize( nbDomains, 0 );
439 if ( nbDomains == 1 )
440 tabID[0] = theMeshDS->ShapeToIndex( tabShape[0] );
444 tabID.resize( 1, 1 );
447 SMDS_ElemIteratorPtr eIt = theMeshDS->elementsIterator();
449 theMeshDS->RemoveFreeElement( eIt->next(), /*sm=*/0 );
450 SMDS_NodeIteratorPtr nIt = theMeshDS->nodesIterator();
451 while ( nIt->more() )
452 theMeshDS->RemoveFreeNode( nIt->next(), /*sm=*/0 );
454 theHelper->SetElementsOnShape( false );
457 int meshID = theHexaOutput->GmfOpenMesh( theFile, GmfRead, &ver, &dim );
459 int nbVerticesInShape = countShape( theMesh, TopAbs_VERTEX );
460 int nbVertices = getNbShape(theHexaOutput, meshID, GmfVertices );
461 int nbCorners = getNbShape(theHexaOutput, meshID, GmfCorners, nbVerticesInShape);
462 if ( nbVertices == 0 )
465 tabCorner.resize( nbCorners );
466 HexoticNode.resize( nbVertices + 1 );
468 // get the shape vertices if the mesh lies on a shape (and this shape has corners)
469 if ( nbCorners > 0 && nbVerticesInShape > 0 )
470 getShape( theMeshDS, TopAbs_VERTEX, tabCorner.data() );
472 int nbNodes = theHexaOutput->GmfStatKwd( meshID, GmfVertices );
475 theHexaOutput->GmfGotoKwd( meshID, GmfVertices );
477 for ( int aHexoticID = 1; aHexoticID <= nbNodes; ++aHexoticID )
479 if ( theAlgo->computeCanceled() )
481 theHexaOutput->GmfGetLin( meshID, GmfVertices, &x, &y, &z, &shapeID );
482 HexoticNode[ aHexoticID ] = theHelper->AddNode( x,y,z );
487 SMDS_MeshNode* node[8];
488 SMDS_MeshElement * aHexoticElement;
490 nbCorners = theHexaOutput->GmfStatKwd( meshID, GmfCorners );
491 if ( nbCorners > 0 && nbDomains > 0 )
493 theHexaOutput->GmfGotoKwd( meshID, GmfCorners );
494 for ( int iElem = 0; iElem < nbCorners; iElem++ )
496 if ( theAlgo->computeCanceled() )
498 theHexaOutput->GmfGetLin( meshID, GmfCorners, &nodeID[0] );
499 node[0] = HexoticNode[ nodeID[0] ];
500 gp_Pnt HexoticPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
501 for ( int i = 0; i < nbCorners; i++ )
503 aVertex = TopoDS::Vertex( tabCorner[i] );
504 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
505 if ( aPnt.Distance( HexoticPnt ) < epsilon )
507 theMeshDS->SetNodeOnVertex( node[0], aVertex );
514 int nbEdges = theHexaOutput->GmfStatKwd( meshID, GmfEdges );
517 theHexaOutput->GmfGotoKwd( meshID, GmfEdges );
518 for ( int iElem = 0; iElem < nbEdges; iElem++ )
520 if ( theAlgo->computeCanceled() )
522 theHexaOutput->GmfGetLin( meshID, GmfEdges, &nodeID[0], &nodeID[1], &shapeID );
523 for ( int i = 0; i < 2; ++i )
525 node[i] = HexoticNode[ nodeID[i]];
526 if ( shapeID > 0 && node[i]->getshapeId() < 1 )
527 theMeshDS->SetNodeOnEdge( node[i], shapeID );
529 aHexoticElement = theHelper->AddEdge( node[0], node[1] );
530 if ( shapeID > 0 && aHexoticElement->getshapeId() < 1 )
531 theMeshDS->SetMeshElementOnShape( aHexoticElement, shapeID );
535 int nbQuad = theHexaOutput->GmfStatKwd( meshID, GmfQuadrilaterals );
538 theHexaOutput->GmfGotoKwd( meshID, GmfQuadrilaterals );
539 for ( int iElem = 0; iElem < nbQuad; iElem++ )
541 if ( theAlgo->computeCanceled() )
543 theHexaOutput->GmfGetLin( meshID, GmfQuadrilaterals,
544 &nodeID[0], &nodeID[1], &nodeID[2], &nodeID[3], &shapeID );
545 for ( int i = 0; i < 4; ++i )
547 node[i] = HexoticNode[ nodeID[i]];
548 if ( shapeID > 0 && node[i]->getshapeId() < 1 )
549 theMeshDS->SetNodeOnFace( node[i], shapeID );
551 aHexoticElement = theHelper->AddFace( node[0], node[1], node[2], node[3] );
552 if ( shapeID > 0 && aHexoticElement->getshapeId() < 1 )
553 theMeshDS->SetMeshElementOnShape( aHexoticElement, shapeID );
557 int nbHexa = theHexaOutput->GmfStatKwd( meshID, GmfHexahedra );
560 theHexaOutput->GmfGotoKwd( meshID, GmfHexahedra );
561 for ( int iElem = 0; iElem < nbHexa; iElem++ )
563 if ( theAlgo->computeCanceled() )
565 theHexaOutput->GmfGetLin( meshID, GmfHexahedra,
566 &nodeID[0], &nodeID[1], &nodeID[2], &nodeID[3],
567 &nodeID[4], &nodeID[5], &nodeID[6], &nodeID[7],
569 for ( int i = 0; i < 8; ++i )
571 node[i] = HexoticNode[ nodeID[i]];
573 if ( nbDomains > 1 ) {
574 hexoticShapeID = shapeID - IdShapeRef;
575 if ( tabID[ hexoticShapeID ] == 0 ) {
576 aShape = findShape(node, aShape, tabShape, tabBox, nbShape);
577 shapeID = aShape.IsNull() ? holeID : theMeshDS->ShapeToIndex( aShape );
578 tabID[ hexoticShapeID ] = shapeID;
581 shapeID = tabID[ hexoticShapeID ];
583 if ( iElem == ( nbHexa - 1) ) {
584 int shapeAssociated = 0;
585 for ( int i=0; i<nbDomains; i++ ) {
587 shapeAssociated += 1;
589 if ( shapeAssociated != nbShape )
590 printWarning(nbShape, "domains", shapeAssociated);
597 if ( shapeID != holeID )
599 for ( int i = 0; i < 8; ++i )
601 if ( node[i]->NbInverseElements( SMDSAbs_Face ) == 0 )
602 theMeshDS->SetNodeInVolume( node[i], shapeID );
604 aHexoticElement = theHelper->AddVolume( node[0], node[3], node[2], node[1],
605 node[4], node[7], node[6], node[5]);
606 if ( aHexoticElement->getshapeId() < 1 )
607 theMeshDS->SetMeshElementOnShape( aHexoticElement, shapeID );
611 std::cout << std::endl;
613 // remove nodes in holes
616 SMESHDS_SubMesh* subMesh = 0;
617 for ( int i = 1; i <= nbNodes; ++i )
618 if ( HexoticNode[i]->NbInverseElements() == 0 )
620 theMeshDS->RemoveFreeNode( HexoticNode[i], subMesh, /*fromGroups=*/false );
624 // avoid "Error: No mesh on sub-shape"
625 if ( theMesh->NbVolumes() > 0 )
627 SMESH_subMesh* smMain = theMesh->GetSubMesh( theMesh->GetShapeToMesh() );
628 SMESH_subMeshIteratorPtr smIt = smMain->getDependsOnIterator( /*includeSelf=*/true );
629 while ( smIt->more() )
631 SMESH_subMesh* sm = smIt->next();
632 if ( !sm->IsMeshComputed() )
633 sm->SetIsAlwaysComputed( true );
640 //=============================================================================
642 * Pass parameters to MG-Hexa
644 //=============================================================================
646 void HexoticPlugin_Hexotic::SetParameters(const HexoticPlugin_Hypothesis* hyp)
649 _hexesMinLevel = hyp->GetHexesMinLevel();
650 _hexesMaxLevel = hyp->GetHexesMaxLevel();
651 _hexesMinSize = hyp->GetMinSize();
652 _hexesMaxSize = hyp->GetMaxSize();
653 _approxAngle = hyp->GetGeomApproxAngle();
654 _hexoticIgnoreRidges = hyp->GetHexoticIgnoreRidges();
655 _hexoticInvalidElements = hyp->GetHexoticInvalidElements();
656 _hexoticSharpAngleThreshold = hyp->GetHexoticSharpAngleThreshold();
657 _hexoticNbProc = hyp->GetHexoticNbProc();
658 _hexoticWorkingDirectory = hyp->GetHexoticWorkingDirectory();
659 _hexoticVerbosity = hyp->GetHexoticVerbosity();
660 _hexoticMaxMemory = hyp->GetHexoticMaxMemory();
661 _hexoticSdMode = hyp->GetHexoticSdMode();
662 _textOptions = hyp->GetAdvancedOption();
663 _sizeMaps = hyp->GetSizeMaps();
664 _nbLayers = hyp->GetNbLayers();
665 _firstLayerSize = hyp->GetFirstLayerSize();
666 _direction = hyp->GetDirection();
667 _growth = hyp->GetGrowth();
668 _facesWithLayers = hyp->GetFacesWithLayers();
669 _imprintedFaces = hyp->GetImprintedFaces();
670 _keepFiles = hyp->GetKeepFiles();
671 _removeLogOnSuccess = hyp->GetRemoveLogOnSuccess();
672 _logInStandardOutput = hyp->GetStandardOutputLog();
675 std::cout << std::endl;
676 std::cout << "WARNING : The MG-Hexa default parameters are taken into account" << std::endl;
677 std::cout << "=======" << std::endl;
678 _hexesMinLevel = hyp->GetDefaultHexesMinLevel();
679 _hexesMaxLevel = hyp->GetDefaultHexesMaxLevel();
680 _hexesMinSize = hyp->GetDefaultMinSize();
681 _hexesMaxSize = hyp->GetDefaultMaxSize();
682 _approxAngle = hyp->GetDefaultGeomApproxAngle();
683 _hexoticIgnoreRidges = hyp->GetDefaultHexoticIgnoreRidges();
684 _hexoticInvalidElements = hyp->GetDefaultHexoticInvalidElements();
685 _hexoticSharpAngleThreshold = hyp->GetDefaultHexoticSharpAngleThreshold();
686 _hexoticNbProc = hyp->GetDefaultHexoticNbProc();
687 _hexoticWorkingDirectory = hyp->GetDefaultHexoticWorkingDirectory();
688 _hexoticVerbosity = hyp->GetDefaultHexoticVerbosity();
689 _hexoticMaxMemory = hyp->GetDefaultHexoticMaxMemory();
690 _hexoticSdMode = hyp->GetDefaultHexoticSdMode();
691 _textOptions = hyp->GetDefaultTextOptions();
692 _sizeMaps = hyp->GetDefaultHexoticSizeMaps();
693 _nbLayers = hyp->GetDefaultNbLayers();
694 _firstLayerSize = hyp->GetDefaultFirstLayerSize();
695 _direction = hyp->GetDefaultDirection();
696 _growth = hyp->GetDefaultGrowth();
697 _facesWithLayers = hyp->GetDefaultFacesWithLayers();
698 _imprintedFaces = hyp->GetDefaultImprintedFaces();
699 _keepFiles = hyp->GetDefaultKeepFiles();
700 _removeLogOnSuccess = hyp->GetDefaultRemoveLogOnSuccess();
701 _logInStandardOutput = hyp->GetDefaultStandardOutputLog();
705 //=======================================================================
706 //function : getSuffix
707 //purpose : Returns a suffix that will be unique for the current process
708 //=======================================================================
710 static TCollection_AsciiString getSuffix()
712 TCollection_AsciiString aSuffix = "";
715 aSuffix += getenv("USER");
717 std::string uname = std::string(getenv("USERNAME"));
718 replace(uname.begin(), uname.end(), ' ', '_');
719 aSuffix += uname.c_str();
722 aSuffix += Kernel_Utils::GetHostname().c_str();
727 aSuffix += _getpid();
733 //================================================================================
735 * \brief Returns a command to run MG-Hexa mesher
737 //================================================================================
740 HexoticPlugin_Hexotic::getHexoticCommand(const TCollection_AsciiString& Hexotic_In,
741 const TCollection_AsciiString& Hexotic_Out,
742 const TCollection_AsciiString& Hexotic_SizeMap_Prefix,
743 const bool forExecutable) const
745 std::cout << std::endl;
746 std::cout << "MG-Hexa execution..." << std::endl;
747 std::cout << _name << " parameters :" << std::endl;
748 std::cout << " " << _name << " Verbosity = " << _hexoticVerbosity << std::endl;
749 std::cout << " " << _name << " Max Memory = " << _hexoticMaxMemory << std::endl;
750 std::cout << " " << _name << " Segments Min Level = " << _hexesMinLevel << std::endl;
751 std::cout << " " << _name << " Segments Max Level = " << _hexesMaxLevel << std::endl;
752 std::cout << " " << _name << " Segments Min Size = " << _hexesMinSize << std::endl;
753 std::cout << " " << _name << " Segments Max Size = " << _hexesMaxSize << std::endl;
754 std::cout << " " << "MG-Hexa can ignore ridges : " << (_hexoticIgnoreRidges ? "yes":"no") << std::endl;
755 std::cout << " " << "MG-Hexa authorize invalide elements : " << ( _hexoticInvalidElements ? "yes":"no") << std::endl;
756 std::cout << " " << _name << " Sharp angle threshold = " << _hexoticSharpAngleThreshold << " degrees" << std::endl;
757 std::cout << " " << _name << " Number of threads = " << _hexoticNbProc << std::endl;
758 std::cout << " " << _name << " Working directory = \"" << _hexoticWorkingDirectory << "\"" << std::endl;
759 std::cout << " " << _name << " Sub. Dom mode = " << _hexoticSdMode << std::endl;
760 std::cout << " " << _name << " Text options = \"" << _textOptions << "\"" << std::endl;
761 std::cout << " " << _name << " Number of layers = " << _nbLayers << std::endl;
762 std::cout << " " << _name << " Size of the first layer = " << _firstLayerSize << std::endl;
763 std::cout << " " << _name << " Direction of the layers = " << ( _direction ? "Inward" : "Outward" ) << std::endl;
764 std::cout << " " << _name << " Growth = " << _growth << std::endl;
765 if (!_facesWithLayers.empty()) {
766 std::cout << " " << _name << " Faces with layers = ";
767 for (size_t i = 0; i < _facesWithLayers.size(); i++)
769 std::cout << _facesWithLayers.at(i);
770 if ((i + 1) != _facesWithLayers.size())
773 std::cout << std::endl;
775 if (!_imprintedFaces.empty()) {
776 std::cout << " " << _name << " Imprinted faces = ";
777 for (size_t i = 0; i < _imprintedFaces.size(); i++)
779 std::cout << _imprintedFaces.at(i);
780 if ((i + 1) != _imprintedFaces.size())
783 std::cout << std::endl;
786 TCollection_AsciiString run_Hexotic("mg-hexa.exe");
788 TCollection_AsciiString minl = " --min_level ", maxl = " --max_level ", angle = " --ridge_angle ";
789 TCollection_AsciiString mins = " --min_size ", maxs = " --max_size ";
790 TCollection_AsciiString in = " --in ", out = " --out ";
791 TCollection_AsciiString sizeMap = " --read_sizemap ";
792 TCollection_AsciiString ignoreRidges = " --compute_ridges no ", invalideElements = " --allow_invalid_elements yes ";
793 TCollection_AsciiString subdom = " --components ";
795 TCollection_AsciiString proc = " --max_number_of_threads ";
797 TCollection_AsciiString verb = " --verbose ";
798 TCollection_AsciiString maxmem = " --max_memory ";
800 TCollection_AsciiString comNbLayers = " --number_of_boundary_layers ";
801 TCollection_AsciiString comFirstLayerSize = " --height_of_the_first_layer ";
802 TCollection_AsciiString comDirection = " --boundary_layers_subdomain_direction ";
803 TCollection_AsciiString comGrowth = " --boundary_layers_geometric_progression ";
804 TCollection_AsciiString comFacesWithLayers = " --boundary_layers_surface_ids ";
805 TCollection_AsciiString comImptintedFaces = " --imprinted_surface_ids ";
807 TCollection_AsciiString minLevel, maxLevel, minSize, maxSize, sharpAngle, mode, nbproc, verbosity, maxMemory,
808 textOptions, nbLayers, firstLayerSize, direction, growth, facesWithLayers, imprintedFaces;
809 minLevel = _hexesMinLevel;
810 maxLevel = _hexesMaxLevel;
811 minSize = _hexesMinSize;
812 maxSize = _hexesMaxSize;
813 sharpAngle = _hexoticSharpAngleThreshold;
814 // Mode translation for mg-tetra 1.1
815 switch ( _hexoticSdMode )
818 mode = "outside_skin_only";
821 mode = "outside_components";
827 mode = "all --manifold_geometry no";
830 nbproc = _hexoticNbProc;
831 verbosity = _hexoticVerbosity;
832 maxMemory = _hexoticMaxMemory;
833 textOptions = (" " + _textOptions + " ").c_str();
834 nbLayers = _nbLayers;
835 firstLayerSize = _firstLayerSize;
836 direction = _direction ? "1" : "-1";
838 for (size_t i = 0; i < _facesWithLayers.size(); i++)
840 facesWithLayers += _facesWithLayers[i];
841 if ((i + 1) != _facesWithLayers.size())
842 facesWithLayers += ",";
844 for (size_t i = 0; i < _imprintedFaces.size(); i++)
846 imprintedFaces += _imprintedFaces[i];
847 if ((i + 1) != _imprintedFaces.size())
848 imprintedFaces += ",";
851 if (_hexoticIgnoreRidges)
852 run_Hexotic += ignoreRidges;
854 if (_hexoticInvalidElements)
855 run_Hexotic += invalideElements;
857 if (_hexesMinSize > 0)
858 run_Hexotic += mins + minSize;
860 if (_hexesMaxSize > 0)
861 run_Hexotic += maxs + maxSize;
863 if (_hexesMinLevel > 0)
864 run_Hexotic += minl + minLevel;
866 if (_hexesMaxLevel > 0)
867 run_Hexotic += maxl + maxLevel;
869 if (_hexoticSharpAngleThreshold > 0)
870 run_Hexotic += angle + sharpAngle;
872 if (_sizeMaps.begin() != _sizeMaps.end() && forExecutable )
873 run_Hexotic += sizeMap + Hexotic_SizeMap_Prefix;
876 _firstLayerSize > 0 &&
878 !_facesWithLayers.empty())
880 run_Hexotic += comNbLayers + nbLayers;
881 run_Hexotic += comFirstLayerSize + firstLayerSize;
882 run_Hexotic += comDirection + direction;
883 run_Hexotic += comGrowth + growth;
884 run_Hexotic += comFacesWithLayers + facesWithLayers;
885 if (!_imprintedFaces.empty())
886 run_Hexotic += comImptintedFaces + imprintedFaces;
889 run_Hexotic += in + Hexotic_In + out + Hexotic_Out;
890 run_Hexotic += subdom + mode;
892 run_Hexotic += proc + nbproc;
894 run_Hexotic += verb + verbosity;
895 run_Hexotic += maxmem + maxMemory;
897 if (!_textOptions.empty())
898 run_Hexotic += textOptions;
900 return run_Hexotic.ToCString();
903 // TODO : this is a duplication of some code found in BLSURFPlugin_BLSURF find a proper
905 TopoDS_Shape HexoticPlugin_Hexotic::entryToShape(std::string entry)
907 GEOM::GEOM_Object_var aGeomObj;
908 TopoDS_Shape S = TopoDS_Shape();
909 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.c_str() );
910 if (!aSObj->_is_nil()) {
911 CORBA::Object_var obj = aSObj->GetObject();
912 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
915 if ( !aGeomObj->_is_nil() )
916 S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
920 //================================================================================
922 * \brief Produces a .mesh file with the size maps informations to give to Hexotic
924 //================================================================================
926 std::vector<std::string> HexoticPlugin_Hexotic::writeSizeMapFile( MG_Hexotic_API* mgInput,
927 std::string sizeMapPrefix )
929 HexoticPlugin_Hypothesis::THexoticSizeMaps::iterator it;
931 std::vector<ControlPnt> points;
932 // Iterate on the size maps
933 for (it=_sizeMaps.begin(); it!=_sizeMaps.end(); it++)
935 // Step 1 : Get the GEOM object entry and the size
936 // from the _sizeMaps infos
937 std::string anEntry = it->first;
938 double aLocalSize = it->second;
939 TopoDS_Shape aShape = entryToShape( anEntry );
941 // Step 2 : Create the points
942 createControlPoints( aShape, aLocalSize, points );
945 // Write the .mesh size map file
947 std::string myVerticesFile = sizeMapPrefix + ".mesh";
948 std::string mySolFile = sizeMapPrefix + ".sol";
952 mgInput->GmfOpenMesh( myVerticesFile.c_str(), GmfWrite, GMFVERSION, GMFDIMENSION );
954 mgInput->GmfOpenMesh( mySolFile.c_str(), GmfWrite, GMFVERSION, GMFDIMENSION );
956 int pointsNumber = points.size();
959 mgInput->GmfSetKwd( verticesFileID, GmfVertices, pointsNumber );
960 // SolAtVertices Keyword
961 int TypTab[] = {GmfSca};
962 mgInput->GmfSetKwd(solFileID, GmfSolAtVertices, pointsNumber, 1, TypTab);
964 // Read the control points information from the vector and write it into the files
966 std::vector<ControlPnt>::const_iterator points_it;
967 for (points_it = points.begin(); points_it != points.end(); points_it++ )
969 mgInput->GmfSetLin( verticesFileID, GmfVertices, points_it->X(), points_it->Y(), points_it->Z(), 0 );
970 ValTab[0] = points_it->Size();
971 mgInput->GmfSetLin( solFileID, GmfSolAtVertices, ValTab);
975 mgInput->GmfCloseMesh( verticesFileID );
976 mgInput->GmfCloseMesh( solFileID );
978 std::vector<std::string> fileNames(2);
979 fileNames[0] = myVerticesFile;
980 fileNames[1] = mySolFile;
985 //=============================================================================
987 * Here we are going to use the MG-Hexa mesher
989 //=============================================================================
991 bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh,
992 const TopoDS_Shape& /*aShape*/)
994 _computeCanceled = false;
996 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
997 TCollection_AsciiString hexahedraMessage;
999 _nbShape = countShape( &aMesh, TopAbs_SOLID ); // we count the number of shapes
1002 // create bounding box for each shape of the compound
1005 TopoDS_Shape *tabShape;
1008 tabShape = new TopoDS_Shape[_nbShape];
1009 tabBox = new double*[_nbShape];
1010 for (int i=0; i<_nbShape; i++)
1011 tabBox[i] = new double[6];
1012 double Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
1014 TopExp_Explorer expBox (meshDS->ShapeToMesh(), TopAbs_SOLID);
1015 for (; expBox.More(); expBox.Next()) {
1016 tabShape[iShape] = expBox.Current();
1017 Bnd_Box BoundingBox;
1018 BRepBndLib::Add(expBox.Current(), BoundingBox);
1019 BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1020 tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
1021 tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
1022 tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
1026 SetParameters(_hypothesis);
1028 TCollection_AsciiString aTmpDir = _hexoticWorkingDirectory.c_str();
1029 TCollection_AsciiString aQuote("");
1032 if ( aTmpDir.Value(aTmpDir.Length()) != '\\' ) aTmpDir += '\\';
1034 if ( aTmpDir.Value(aTmpDir.Length()) != '/' ) aTmpDir += '/';
1036 TCollection_AsciiString Hexotic_In(""), Hexotic_Out, Hexotic_SizeMap_Prefix;
1037 TCollection_AsciiString modeFile_In( "chmod 666 " ), modeFile_Out( "chmod 666 " );
1038 TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic"+getSuffix()+".log"; // log
1040 std::map <int,int> aSmdsToHexoticIdMap;
1041 std::map <int,const SMDS_MeshNode*> aHexoticIdToNodeMap;
1043 MG_Hexotic_API mgHexa( _computeCanceled, _progress );
1045 Hexotic_Out = aTmpDir + "Hexotic"+getSuffix()+"_Out.mesh";
1046 #ifdef WITH_BLSURFPLUGIN
1047 bool defaultInputFile = true;
1048 if (_blsurfHypo && _blsurfHypo->GetElementType() == BLSURFPlugin_Hypothesis::Triangles ) {
1049 Hexotic_In = _blsurfHypo->GetGMFFile().c_str();
1050 if ( !Hexotic_In.IsEmpty() &&
1051 SMESH_File( _blsurfHypo->GetGMFFile() ).exists() )
1053 MESSAGE("Use output file from blsurf as input file from hexotic: " << Hexotic_In);
1054 mgHexa.SetUseExecutable();
1055 defaultInputFile = false;
1058 if (defaultInputFile) {
1060 Hexotic_In = aTmpDir + "Hexotic"+getSuffix()+"_In.mesh";
1061 removeHexoticFiles(Hexotic_In, Hexotic_Out);
1062 splitQuads(aMesh); // quadrangles are no longer acceptable as input
1063 if ( mgHexa.IsExecutable() )
1065 std::cout << std::endl;
1066 std::cout << "Creating MG-Hexa input mesh file : " << Hexotic_In << std::endl;
1068 writeInput( &mgHexa, Hexotic_In.ToCString(), meshDS );
1069 #ifdef WITH_BLSURFPLUGIN
1072 removeFile( Hexotic_Out );
1076 Hexotic_SizeMap_Prefix = aTmpDir + "Hexotic_SizeMap" + getSuffix();
1077 std::vector<std::string> sizeMapFiles = writeSizeMapFile( &mgHexa, Hexotic_SizeMap_Prefix.ToCString() );
1079 std::string run_Hexotic = getHexoticCommand(aQuote + Hexotic_In + aQuote, aQuote + Hexotic_Out + aQuote, Hexotic_SizeMap_Prefix, mgHexa.IsExecutable() );
1080 run_Hexotic += std::string(" 1> ") + aQuote.ToCString() + aLogFileName.ToCString() + aQuote.ToCString(); // dump into file
1081 mgHexa.SetLogFile( aLogFileName.ToCString() );
1082 std::cout << "Creating MG-Hexa log file : " << aLogFileName << std::endl;
1084 std::cout << std::endl;
1085 std::cout << "MG-Hexa command : " << run_Hexotic << std::endl;
1087 if ( mgHexa.IsExecutable() )
1090 modeFile_In += Hexotic_In;
1091 system( modeFile_In.ToCString() );
1094 aSmdsToHexoticIdMap.clear();
1095 aHexoticIdToNodeMap.clear();
1097 MESSAGE("HexoticPlugin_Hexotic::Compute");
1101 Ok = mgHexa.Compute( run_Hexotic, errStr ); // run
1108 if ( mgHexa.IsExecutable() && SMESH_File( Hexotic_Out.ToCString() ).exists() )
1111 modeFile_Out += Hexotic_Out;
1112 system( modeFile_Out.ToCString() );
1115 SMESH_MesherHelper aHelper( aMesh );
1117 Ok = readResult( &mgHexa, Hexotic_Out.ToCString(),
1119 &aHelper, _nbShape, tabShape, tabBox );
1121 std::string log = mgHexa.GetLog();
1122 hexahedraMessage = "failed";
1125 hexahedraMessage = "success";
1126 if ( _removeLogOnSuccess )
1127 removeFile( aLogFileName );
1129 else if ( !log.empty() )
1131 if( _computeCanceled )
1132 error( "interruption initiated by user" );
1135 // get problem description from the log file
1136 char msgLic[] = " Dlim ";
1137 const char* fileBeg = &log[0], *fileEnd = fileBeg + log.size();
1138 if ( std::search( fileBeg, fileEnd, msgLic, msgLic+strlen(msgLic)) != fileEnd )
1139 error("Licence problems.");
1142 else if ( !errStr.empty() )
1144 // the log file is empty
1145 removeFile( aLogFileName );
1146 INFOS( "MG-Hexa Error, " << errStr);
1147 error(COMPERR_ALGO_FAILED, errStr);
1150 if ( !Ok && mgHexa.IsExecutable() )
1151 std::cout << "Problem with MG-Hexa output file " << Hexotic_Out.ToCString() << std::endl;
1155 if (! Ok && _computeCanceled )
1156 removeFile( aLogFileName );
1157 removeFile(Hexotic_Out);
1158 removeFile(Hexotic_In);
1159 for ( size_t i = 0; i < sizeMapFiles.size(); i++ )
1160 removeFile( sizeMapFiles[i].c_str() );
1162 std::cout << "Hexahedra meshing " << hexahedraMessage << std::endl;
1163 std::cout << std::endl;
1166 for (int i=0; i<_nbShape; i++)
1167 delete [] tabBox[i];
1176 //=============================================================================
1178 * \brief Computes mesh without geometry
1179 * \param aMesh - the mesh
1180 * \param aHelper - helper that must be used for adding elements to \aaMesh
1181 * \retval bool - is a success
1183 * The method is called if ( !aMesh->HasShapeToMesh() )
1185 //=============================================================================
1187 bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper)
1189 _computeCanceled = false;
1192 TCollection_AsciiString hexahedraMessage;
1193 TCollection_AsciiString aQuote("");
1197 SetParameters(_hypothesis);
1199 TCollection_AsciiString aTmpDir = _hexoticWorkingDirectory.c_str();//getTmpDir();
1200 TCollection_AsciiString Hexotic_In, Hexotic_Out, Hexotic_SizeMap_Prefix;
1201 TCollection_AsciiString modeFile_In( "chmod 666 " ), modeFile_Out( "chmod 666 " );
1202 TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic"+getSuffix()+".log"; // log
1204 std::map <int,int> aSmdsToHexoticIdMap;
1205 std::map <int,const SMDS_MeshNode*> aHexoticIdToNodeMap;
1207 Hexotic_In = aTmpDir + "Hexotic"+getSuffix()+"_In.mesh";
1208 Hexotic_Out = aTmpDir + "Hexotic"+getSuffix()+"_Out.mesh";
1209 Hexotic_SizeMap_Prefix = aTmpDir + "Hexotic_SizeMap";
1211 MG_Hexotic_API mgHexa( _computeCanceled, _progress );
1213 std::vector<std::string> sizeMapFiles = writeSizeMapFile( &mgHexa, Hexotic_SizeMap_Prefix.ToCString() );
1215 std::string run_Hexotic = getHexoticCommand(aQuote + Hexotic_In + aQuote, aQuote + Hexotic_Out + aQuote, Hexotic_SizeMap_Prefix, mgHexa.IsExecutable());
1216 run_Hexotic += std::string(" 1> ") + aQuote.ToCString() + aLogFileName.ToCString() + aQuote.ToCString(); // dump into file
1217 mgHexa.SetLogFile( aLogFileName.ToCString() );
1218 std::cout << "Creating MG-Hexa log file : " << aLogFileName << std::endl;
1220 removeHexoticFiles(Hexotic_In, Hexotic_Out);
1222 splitQuads(aMesh); // quadrangles are no longer acceptable as input
1224 std::cout << std::endl;
1225 std::cout << "Creating MG-Hexa input mesh file : " << Hexotic_In << std::endl;
1226 writeInput( &mgHexa, Hexotic_In.ToCString(), aHelper->GetMeshDS() );
1227 if ( mgHexa.IsExecutable() )
1230 modeFile_In += Hexotic_In;
1231 system( modeFile_In.ToCString() );
1234 aSmdsToHexoticIdMap.clear();
1235 aHexoticIdToNodeMap.clear();
1237 MESSAGE("HexoticPlugin_Hexotic::Compute");
1239 std::cout << std::endl;
1240 std::cout << "MG-Hexa command : " << run_Hexotic << std::endl;
1243 Ok = mgHexa.Compute( run_Hexotic, errStr ); // run
1249 if ( mgHexa.IsExecutable() && SMESH_File( Hexotic_Out.ToCString() ).exists() )
1251 modeFile_Out += Hexotic_Out;
1252 system( modeFile_Out.ToCString() );
1255 Ok = Ok && readResult( &mgHexa, Hexotic_Out.ToCString(), this, aHelper );
1257 std::string log = mgHexa.GetLog();
1260 hexahedraMessage = "success";
1264 hexahedraMessage = "failed";
1265 if ( mgHexa.IsExecutable() )
1266 std::cout << "Problem with MG-Hexa output file " << Hexotic_Out << std::endl;
1268 if ( log.find( " license " ) != std::string::npos ||
1269 log.find( " Dlim " ) != std::string::npos )
1270 error("License problems.");
1272 if ( !errStr.empty() )
1275 std::cout << "Hexahedra meshing " << hexahedraMessage << std::endl;
1276 std::cout << std::endl;
1278 if(_computeCanceled)
1279 return error(SMESH_Comment("interruption initiated by user"));
1280 removeFile(Hexotic_Out);
1281 removeFile(Hexotic_In);
1283 removeFile(aLogFileName);
1284 for( size_t i=0; i<sizeMapFiles.size(); i++)
1286 removeFile( TCollection_AsciiString(sizeMapFiles[i].c_str()) );
1291 //=============================================================================
1295 //=============================================================================
1297 bool HexoticPlugin_Hexotic::Evaluate(SMESH_Mesh& aMesh,
1298 const TopoDS_Shape& aShape,
1299 MapShapeNbElems& aResMap)
1301 std::vector<smIdType> aResVec(SMDSEntity_Last);
1302 for(smIdType i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1303 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
1304 aResMap.insert(std::make_pair(sm,aResVec));
1306 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1307 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Evaluation is not implemented",this));
1312 void HexoticPlugin_Hexotic::CancelCompute()
1314 _computeCanceled = true;
1317 TCollection_AsciiString aTmpDir = _hexoticWorkingDirectory.c_str(); //getTmpDir();
1318 TCollection_AsciiString Hexotic_In = aTmpDir + "Hexotic_In.mesh";
1319 TCollection_AsciiString cmd = TCollection_AsciiString("ps ux | grep ") + Hexotic_In;
1320 cmd += TCollection_AsciiString(" | grep -v grep | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1");
1321 system( cmd.ToCString() );