#ifdef _DEBUG_
#define DUMP(txt) \
-// cout << txt
+// std::cout << txt
#else
#define DUMP(txt)
#endif
static char* readMapIntLine(char* ptr, int tab[]) {
long int intVal;
- cout << endl;
+ std::cout << std::endl;
for ( int i=0; i<17; i++ ) {
intVal = strtol(ptr, &ptr, 10);
}
std::cout << std::endl;
std::cout << "Start writing in 'points' file ..." << std::endl;
-// theFile << space << nbNodes - nbEnforcedVerteces << std::endl;
theFile << space << nbNodes << std::endl;
// Loop from 1 to NB_NODES
GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexIt;
const TopoDS_Shape shapeToMesh = theMesh->ShapeToMesh();
for(vertexIt = theEnforcedVerteces.begin() ; vertexIt != theEnforcedVerteces.end() ; ++vertexIt) {
- double x = vertexIt->first->x;
- double y = vertexIt->first->y;
- double z = vertexIt->first->z;
+ double x = vertexIt->first[0];
+ double y = vertexIt->first[1];
+ double z = vertexIt->first[2];
// Test if point is inside shape to mesh
gp_Pnt myPoint(x,y,z);
BRepClass3d_SolidClassifier scl(shapeToMesh);
const vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
GHS3DPlugin_Hypothesis::TSizeMapVertexValues & theEnforcedVerteces)
{
- std::cout << "writePoints(ofstream &,SMESHDS_Mesh *,const vector <const SMDS_MeshNode*> &,GHS3DPlugin_Hypothesis::TSizeMapVertexValues &)" << std::endl;
// record structure:
//
// NB_NODES
const SMDS_MeshNode* node;
// NB_NODES
- cout << endl;
- cout << "The initial 2D mesh contains :" << endl;
- cout << " " << nbNodes << " nodes" << endl;
- cout << " " << nbEnforcedVerteces << " enforced vertices" << endl;
+ std::cout << std::endl;
+ std::cout << "The initial 2D mesh contains :" << std::endl;
+ std::cout << " " << nbNodes << " nodes" << std::endl;
+ std::cout << " " << nbEnforcedVerteces << " enforced vertices" << std::endl;
std::cout << std::endl;
std::cout << "Start writing in 'points' file ..." << std::endl;
theFile << space << nbNodes << std::endl;
<< space << node->Z()
<< space << dummyint;
- theFile << endl;
+ theFile << std::endl;
}
// Iterate over the enforced verteces
GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexIt;
+ const TopoDS_Shape shapeToMesh = theMesh->ShapeToMesh();
for(vertexIt = theEnforcedVerteces.begin() ; vertexIt != theEnforcedVerteces.end() ; ++vertexIt) {
- std::cout << "Adding enforced vertex (" << vertexIt->first->x << "," << vertexIt->first->y <<"," << vertexIt->first->z << ") = " << vertexIt->second << std::endl;
-
- // X Y Z PHY_SIZE DUMMY_INT
- theFile
- << space << vertexIt->first->x
- << space << vertexIt->first->y
- << space << vertexIt->first->z
- << space << vertexIt->second
- << space << dummyint;
+ double x = vertexIt->first[0];
+ double y = vertexIt->first[1];
+ double z = vertexIt->first[2];
+ // Test if point is inside shape to mesh
+ gp_Pnt myPoint(x,y,z);
+ BRepClass3d_SolidClassifier scl(shapeToMesh);
+ scl.Perform(myPoint, 1e-7);
+ TopAbs_State result = scl.State();
+ if ( result == TopAbs_IN ) {
+ std::cout << "Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second << std::endl;
- theFile << std::endl;
+ // X Y Z PHY_SIZE DUMMY_INT
+ theFile
+ << space << x
+ << space << y
+ << space << z
+ << space << vertexIt->second
+ << space << dummyint;
+
+ theFile << std::endl;
+ }
}
- std::cout << endl;
+ std::cout << std::endl;
std::cout << "End writing in 'points' file." << std::endl;
return true;
OCC_CATCH_SIGNALS;
tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles );
#ifdef _DEBUG_
- cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << endl;
+ std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
#endif
} catch ( Standard_Failure ) {
} catch (...) {}
}
if ( nbElems )
- cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << endl;
+ std::cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << std::endl;
munmap(mapPtr, length);
close(fileOpen);
#ifdef _DEBUG_
if ( shapeIDs.size() != nbShape ) {
- cout << "Only " << shapeIDs.size() << " solids of " << nbShape << " found" << endl;
+ std::cout << "Only " << shapeIDs.size() << " solids of " << nbShape << " found" << std::endl;
for (int i=0; i<nbShape; i++) {
shapeID = theMeshDS->ShapeToIndex( tabShape[i] );
if ( shapeIDs.find( shapeID ) == shapeIDs.end() )
- cout << " Solid #" << shapeID << " not found" << endl;
+ std::cout << " Solid #" << shapeID << " not found" << std::endl;
}
}
#endif
theMeshDS->SetMeshElementOnShape( aTet, shapeID );
}
if ( nbElems )
- cout << nbElems << " tetrahedrons have been associated to " << nbTriangle << " shapes" << endl;
+ std::cout << nbElems << " tetrahedrons have been associated to " << nbTriangle << " shapes" << std::endl;
munmap(mapPtr, length);
close(fileOpen);
cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
- cout << endl;
- cout << "Ghs3d execution..." << endl;
- cout << cmd << endl;
+ std::cout << std::endl;
+ std::cout << "Ghs3d execution..." << std::endl;
+ std::cout << cmd << std::endl;
system( cmd.ToCString() ); // run
- cout << endl;
- cout << "End of Ghs3d execution !" << endl;
+ std::cout << std::endl;
+ std::cout << "End of Ghs3d execution !" << std::endl;
// --------------
// read a result
int fileOpen;
fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
if ( fileOpen < 0 ) {
- cout << endl;
- cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << endl;
- cout << "Log: " << aLogFileName << endl;
+ std::cout << std::endl;
+ std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl;
+ std::cout << "Log: " << aLogFileName << std::endl;
Ok = false;
}
else {
OSD_File( aBadResFileName ).Remove();
OSD_File( aBbResFileName ).Remove();
}
- cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
+ std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
if ( !Ok )
- cout << "not ";
- cout << "treated !" << endl;
- cout << endl;
+ std::cout << "not ";
+ std::cout << "treated !" << std::endl;
+ std::cout << std::endl;
_nbShape = 0; // re-initializing _nbShape for the next Compute() method call
delete [] tabShape;
int fileOpen;
fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
if ( fileOpen < 0 ) {
- cout << endl;
- cout << "Error when opening the " << aResultFileName.ToCString() << " file" << endl;
- cout << "Log: " << aLogFileName << endl;
- cout << endl;
+ std::cout << std::endl;
+ std::cout << "Error when opening the " << aResultFileName.ToCString() << " file" << std::endl;
+ std::cout << "Log: " << aLogFileName << std::endl;
+ std::cout << std::endl;
Ok = false;
}
else {
//function : SetWorkingDirectory
//=======================================================================
-void GHS3DPlugin_Hypothesis::SetWorkingDirectory(const string& path)
+void GHS3DPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
{
if ( myWorkingDirectory != path ) {
myWorkingDirectory = path;
//function : GetWorkingDirectory
//=======================================================================
-string GHS3DPlugin_Hypothesis::GetWorkingDirectory() const
+std::string GHS3DPlugin_Hypothesis::GetWorkingDirectory() const
{
return myWorkingDirectory;
}
//function : SetTextOption
//=======================================================================
-void GHS3DPlugin_Hypothesis::SetTextOption(const string& option)
+void GHS3DPlugin_Hypothesis::SetTextOption(const std::string& option)
{
if ( myTextOption != option ) {
myTextOption = option;
//function : GetTextOption
//=======================================================================
-string GHS3DPlugin_Hypothesis::GetTextOption() const
+std::string GHS3DPlugin_Hypothesis::GetTextOption() const
{
return myTextOption;
}
void GHS3DPlugin_Hypothesis::SetSizeMapVertex(double x, double y, double z, double size)
{
- std::cout << "GHS3DPlugin_Hypothesis::SetSizeMapVertex(x,y,z,size)" << std::endl;
- bool found = false;
- TSizeMapVertexValues::iterator it;
- for (it = mySizeMapVerteces.begin() ; it != mySizeMapVerteces.end() ; ++it)
- if ((it->first->x == x) and (it->first->y == y) and (it->first->z == z)) {
- it->second = size;
- found = true;
- break;
- }
- if (not found) {
- GHS3DSizeMapVertex* coord = new GHS3DSizeMapVertex;
- coord->x = x;
- coord->y = y;
- coord->z = z;
- mySizeMapVerteces[coord] = size;
- }
+ std::vector<double> coord(3);
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
+ mySizeMapVerteces[coord] = size;
NotifySubMeshesHypothesisModification();
}
double GHS3DPlugin_Hypothesis::GetSizeMapVertex(double x, double y, double z)
throw (std::invalid_argument)
{
-// double coord[] = {x,y,z};
- TSizeMapVertexValues::const_iterator it;
- for (it = mySizeMapVerteces.begin() ; it != mySizeMapVerteces.end() ; ++it) {
- if ((it->first->x == x) and (it->first->y == y) and (it->first->z == z))
- return it->second;
- }
-// if (mySizeMapVerteces.count(coord)>0)
-// return mySizeMapVerteces[coord];
- ostringstream msg ;
+ std::vector<double> coord(3);
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
+ if (mySizeMapVerteces.count(coord)>0)
+ return mySizeMapVerteces[coord];
+ std::ostringstream msg ;
msg << "No enforced vertex at " << x << ", " << y << ", " << z;
throw std::invalid_argument(msg.str());
}
void GHS3DPlugin_Hypothesis::RemoveSizeMapVertex(double x, double y, double z)
throw (std::invalid_argument)
{
- TSizeMapVertexValues::const_iterator it;
- bool found = false;
- for (it = mySizeMapVerteces.begin() ; it != mySizeMapVerteces.end() ; ++it)
- if ((it->first->x == x) and (it->first->y == y) and (it->first->z == z)) {
- found = true;
- break;
+ std::vector<double> coord(3);
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
+ TSizeMapVertexValues::iterator it = mySizeMapVerteces.find(coord);
+ if (it != mySizeMapVerteces.end()) {
+ mySizeMapVerteces.erase(it);
+ NotifySubMeshesHypothesisModification();
+ return;
}
- if (found) {
- mySizeMapVerteces.erase(it->first);
- NotifySubMeshesHypothesisModification();
- }
- else {
- ostringstream msg ;
+ std::ostringstream msg ;
msg << "No enforced vertex at " << x << ", " << y << ", " << z;
throw std::invalid_argument(msg.str());
- }
}
//=======================================================================
//function : DefaultWorkingDirectory
//=======================================================================
-string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
+std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
{
TCollection_AsciiString aTmpDir;
GHS3DPlugin_Hypothesis::TSizeMapVertexValues GHS3DPlugin_Hypothesis::DefaultSizeMapVerteces()
{
- std::cout << "GHS3DPlugin_Hypothesis::DefaultSizeMapVerteces()" << std::endl;
return GHS3DPlugin_Hypothesis::TSizeMapVertexValues();
}
//function : SaveTo
//=======================================================================
-ostream & GHS3DPlugin_Hypothesis::SaveTo(ostream & save)
+std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
{
save << (int) myToMeshHoles << " ";
save << myMaximumMemory << " ";
save << myVerboseLevel << " ";
save << (int)myToCreateNewNodes << " ";
save << (int)myToUseBoundaryRecoveryVersion << " ";
+ save << "__OPTIONS_BEGIN__ ";
save << myTextOption << " ";
+ save << " __OPTIONS_END__ ";
-// if (mySizeMapVerteces.size() >= 4) {
-// save << "__SIZEMAP_BEGIN__" << " ";
-// for (int i=0 ; i<mySizeMapVerteces.size(); i++)
-// save << mySizeMapVerteces.at(i) << " ";
-// save << "__SIZEMAP_END__" << " ";
-// }
+
+ TSizeMapVertexValues::iterator it = mySizeMapVerteces.begin();
+ if (it != mySizeMapVerteces.end()) {
+ save << "__ENFORCED_VERTECES_BEGIN__ ";
+ for ( ; it != mySizeMapVerteces.end(); ++it ) {
+ save << it->first[0] << " "
+ << it->first[1] << " "
+ << it->first[2] << " "
+ << it->second << " ";
+ }
+ save << "__ENFORCED_VERTECES_END__ ";
+ }
+
return save;
}
//function : LoadFrom
//=======================================================================
-istream & GHS3DPlugin_Hypothesis::LoadFrom(istream & load)
-{
- bool isOK = true;
- int i;
-
- isOK = (load >> i);
- if (isOK)
- myToMeshHoles = i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> i);
- if (isOK)
- myMaximumMemory = i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> i);
- if (isOK)
- myInitialMemory = i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> i);
- if (isOK)
- myOptimizationLevel = i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> myWorkingDirectory);
- if (isOK) {
- if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
- myKeepFiles = false;
- myWorkingDirectory.clear();
+std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
+{
+ bool isOK = true;
+ int i;
+
+ isOK = (load >> i);
+ if (isOK)
+ myToMeshHoles = i;
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+ isOK = (load >> i);
+ if (isOK)
+ myMaximumMemory = i;
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+ isOK = (load >> i);
+ if (isOK)
+ myInitialMemory = i;
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+ isOK = (load >> i);
+ if (isOK)
+ myOptimizationLevel = i;
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+ isOK = (load >> myWorkingDirectory);
+ if (isOK) {
+ if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
+ myKeepFiles = false;
+ myWorkingDirectory.clear();
+ }
+ else if ( myWorkingDirectory == "1" ) {
+ myKeepFiles = true;
+ myWorkingDirectory.clear();
+ }
}
- else if ( myWorkingDirectory == "1" ) {
- myKeepFiles = true;
- myWorkingDirectory.clear();
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+ if ( !myWorkingDirectory.empty() ) {
+ isOK = (load >> i);
+ if (isOK)
+ myKeepFiles = i;
+ else
+ load.clear(ios::badbit | load.rdstate());
}
- }
- else
- load.clear(ios::badbit | load.rdstate());
-
- if ( !myWorkingDirectory.empty() ) {
+
isOK = (load >> i);
if (isOK)
- myKeepFiles = i;
+ myVerboseLevel = (short) i;
else
- load.clear(ios::badbit | load.rdstate());
- }
+ load.clear(ios::badbit | load.rdstate());
+
+ isOK = (load >> i);
+ if (isOK)
+ myToCreateNewNodes = (bool) i;
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+ isOK = (load >> i);
+ if (isOK)
+ myToUseBoundaryRecoveryVersion = (bool) i;
+ else
+ load.clear(ios::badbit | load.rdstate());
+
+// isOK = (load >> myTextOption);
+// while (isOK) {
+// std::string txt;
+// if (load >> txt) {
+// myTextOption += " ";
+// myTextOption += txt;
+// }
+// else
+// isOK = false;
+// }
+// // else
+// // load.clear(ios::badbit | load.rdstate());
+
+
+ std::string separator;
+ bool hasOptions = false;
+ bool hasEnforcedVerteces = false;
+ isOK = (load >> separator);
- isOK = (load >> i);
- if (isOK)
- myVerboseLevel = (short) i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> i);
- if (isOK)
- myToCreateNewNodes = (bool) i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> i);
- if (isOK)
- myToUseBoundaryRecoveryVersion = (bool) i;
- else
- load.clear(ios::badbit | load.rdstate());
-
- isOK = (load >> myTextOption);
- while (isOK) {
- string txt;
- if (load >> txt) {
- myTextOption += " ";
- myTextOption += txt;
+ if (isOK)
+ if (separator == "__OPTIONS_BEGIN__")
+ hasOptions = true;
+ else if (separator == "__ENFORCED_VERTECES_BEGIN__")
+ hasEnforcedVerteces = true;
+
+ if (hasOptions) {
+ std::string txt;
+ isOK = (load >> myTextOption);
+ while (isOK) {
+ if (myTextOption == "__OPTIONS_END__") {
+ isOK = false;
+ break;
+ }
+ if (load >> txt) {
+ if (txt == "__OPTIONS_END__") {
+ isOK = false;
+ break;
+ }
+ myTextOption += " ";
+ myTextOption += txt;
+ }
+ else
+ isOK = false;
+ }
+ }
+
+ if (hasOptions) {
+ isOK = (load >> separator);
+ if (isOK)
+ if (separator == "__ENFORCED_VERTECES_BEGIN__")
+ hasEnforcedVerteces = true;
+ }
+
+ if (hasEnforcedVerteces) {
+ std::string txt;
+ double x,y,z,size;
+ while (isOK) {
+ isOK = (load >> txt);
+ if (isOK) {
+ if (txt == "__ENFORCED_VERTECES_END__") {
+ isOK = false;
+ break;
+ }
+ x = atof(txt.c_str());
+ isOK = (load >> y >> z >> size);
+ }
+ if (isOK) {
+ std::vector<double> coord;
+ coord.push_back(x);
+ coord.push_back(y);
+ coord.push_back(z);
+ mySizeMapVerteces[ coord ] = size;
+ }
+ }
}
- else
- isOK = false;
- }
-// else
-// load.clear(ios::badbit | load.rdstate());
return load;
}
*/
//================================================================================
-string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
+std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
const bool hasShapeToMesh)
{
#ifndef WIN32
TCollection_AsciiString cmd( "ghs3d.exe" );
#endif
// check if any option is overridden by hyp->myTextOption
- bool m = hyp ? ( hyp->myTextOption.find("-m") == string::npos ) : true;
- bool M = hyp ? ( hyp->myTextOption.find("-M") == string::npos ) : true;
- bool c = hyp ? ( hyp->myTextOption.find("-c") == string::npos ) : true;
- bool o = hyp ? ( hyp->myTextOption.find("-o") == string::npos ) : true;
- bool p0= hyp ? ( hyp->myTextOption.find("-p0")== string::npos ) : true;
- bool C = hyp ? ( hyp->myTextOption.find("-C") == string::npos ) : true;
- bool v = hyp ? ( hyp->myTextOption.find("-v") == string::npos ) : true;
+ bool m = hyp ? ( hyp->myTextOption.find("-m") == std::string::npos ) : true;
+ bool M = hyp ? ( hyp->myTextOption.find("-M") == std::string::npos ) : true;
+ bool c = hyp ? ( hyp->myTextOption.find("-c") == std::string::npos ) : true;
+ bool o = hyp ? ( hyp->myTextOption.find("-o") == std::string::npos ) : true;
+ bool p0= hyp ? ( hyp->myTextOption.find("-p0")== std::string::npos ) : true;
+ bool C = hyp ? ( hyp->myTextOption.find("-C") == std::string::npos ) : true;
+ bool v = hyp ? ( hyp->myTextOption.find("-v") == std::string::npos ) : true;
// if use boundary recovery version, few options are allowed
bool useBndRecovery = !C;
*/
//================================================================================
-string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
+std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
{
- string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
+ std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
const char lastChar = *aTmpDir.rbegin();
#ifdef WIN32
if(lastChar != '\\') aTmpDir+='\\';
#include "GHS3DPlugin_Defs.hxx"
#include <SMESH_Hypothesis.hxx>
+#include <utilities.h>
+
#include <stdexcept>
#include <map>
+#include <vector>
#include <cstdio>
-using namespace std;
class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis: public SMESH_Hypothesis
{
/*!
* Path to working directory
*/
- void SetWorkingDirectory(const string& path);
- string GetWorkingDirectory() const;
+ void SetWorkingDirectory(const std::string& path);
+ std::string GetWorkingDirectory() const;
/*!
* To keep working files or remove them. Log file remains in case of errors anyway.
*/
/*!
* To set hiden/undocumented/advanced options
*/
- void SetTextOption(const string& option);
- string GetTextOption() const;
+ void SetTextOption(const std::string& option);
+ std::string GetTextOption() const;
/*!
* To set an enforced vertex
*/
- typedef struct
- {
- double x;
- double y;
- double z;
- } GHS3DSizeMapVertex;
-
- typedef std::map<GHS3DSizeMapVertex*,double> TSizeMapVertexValues;
+ typedef std::map<std::vector<double>,double> TSizeMapVertexValues;
void SetSizeMapVertex(double x, double y, double z, double size);
double GetSizeMapVertex(double x, double y, double z) throw (std::invalid_argument);
void RemoveSizeMapVertex(double x, double y, double z) throw (std::invalid_argument);
static short DefaultMaximumMemory();
static short DefaultInitialMemory();
static short DefaultOptimizationLevel();
- static string DefaultWorkingDirectory();
+ static std::string DefaultWorkingDirectory();
static bool DefaultKeepFiles();
static short DefaultVerboseLevel();
static bool DefaultToCreateNewNodes();
static TSizeMapVertexValues GetEnforcedVerteces(const GHS3DPlugin_Hypothesis* hyp);
// Persistence
- virtual ostream & SaveTo(ostream & save);
- virtual istream & LoadFrom(istream & load);
- friend GHS3DPLUGIN_EXPORT ostream & operator <<(ostream & save, GHS3DPlugin_Hypothesis & hyp);
- friend GHS3DPLUGIN_EXPORT istream & operator >>(istream & load, GHS3DPlugin_Hypothesis & hyp);
+ virtual std::ostream & SaveTo(std::ostream & save);
+ virtual std::istream & LoadFrom(std::istream & load);
+ friend GHS3DPLUGIN_EXPORT std::ostream & operator <<(std::ostream & save, GHS3DPlugin_Hypothesis & hyp);
+ friend GHS3DPLUGIN_EXPORT std::istream & operator >>(std::istream & load, GHS3DPlugin_Hypothesis & hyp);
/*!
* \brief Does nothing
short myInitialMemory;
short myOptimizationLevel;
bool myKeepFiles;
- string myWorkingDirectory;
+ std::string myWorkingDirectory;
short myVerboseLevel;
bool myToCreateNewNodes;
bool myToUseBoundaryRecoveryVersion;
- string myTextOption;
+ std::string myTextOption;
TSizeMapVertexValues mySizeMapVerteces;
};
GHS3DPlugin::GHS3DSizeMapVertexList* GHS3DPlugin_Hypothesis_i::GetSizeMapVerteces()
{
- std::cout << "GHS3DPlugin_Hypothesis_i::GetSizeMapVerteces()" << std::endl;
ASSERT(myBaseImpl);
GHS3DPlugin::GHS3DSizeMapVertexList_var result = new GHS3DPlugin::GHS3DSizeMapVertexList();
const ::GHS3DPlugin_Hypothesis::TSizeMapVertexValues sizeMaps = this->GetImpl()->GetSizeMapVerteces();
int size = sizeMaps.size();
-// std::cout << "size: " << size << std::endl;
result->length( size );
::GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator it;
int i = 0;
for (it = sizeMaps.begin() ; it != sizeMaps.end(); it++ ) {
GHS3DPlugin::GHS3DSizeMapVertex_var myVertex = new GHS3DPlugin::GHS3DSizeMapVertex();
- myVertex->x = it->first->x;
- myVertex->y = it->first->y;
- myVertex->z = it->first->z;
+ myVertex->x = it->first[0];
+ myVertex->y = it->first[1];
+ myVertex->z = it->first[2];
myVertex->size = it->second;
result[i]=myVertex;
i++;
void GHS3DPlugin_Hypothesis_i::ClearSizeMapVerteces()
{
- std::cout << "GHS3DPlugin_Hypothesis_i::ClearSizeMapVerteces()" << std::endl;
ASSERT(myBaseImpl);
this->GetImpl()->ClearSizeMapVerteces();
}
#include <SMESHGUI_Utils.h>
#include <SMESHGUI_HypothesesUtils.h>
-#include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm)
-
-#include <SUIT_MessageBox.h>
#include <SUIT_Session.h>
-#include <SUIT_FileDlg.h>
+#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
+#include <SUIT_FileDlg.h>
#include <SalomeApp_Tools.h>
-#include <QLabel>
#include <QComboBox>
+#include <QLabel>
#include <QFrame>
-#include <QGridLayout>
#include <QVBoxLayout>
+#include <QGridLayout>
#include <QLineEdit>
#include <QCheckBox>
#include <QTabWidget>
#include <QModelIndexList>
#include <stdexcept>
+#include <utilities.h>
enum {
STD_TAB = 0,
if (ok) {
model->setData(index, value, Qt::EditRole);
- std::cout << "Value " << value << " was set at index(" << index.row() << "," << index.column() << ")" << std::endl;
- std::cout << "model->data(index).toDouble(): " << model->data(index).toDouble() << std::endl;
+ MESSAGE("Value " << value << " was set at index(" << index.row() << "," << index.column() << ")");
}
}
for (int i=0 ; i < rowCount ; i++) {
double myX = mySmpModel->data(mySmpModel->index(i, SMP_X_COLUMN)).toDouble();
if (myX == x) {
- std::cout << "Found x value " << x << " at row " << i << std::endl;
+ MESSAGE("Found x value " << x << " at row " << i);
double myY = mySmpModel->data(mySmpModel->index(i, SMP_Y_COLUMN)).toDouble();
if (myY == y) {
- std::cout << "Found y value " << y << " at row " << i << std::endl;
+ MESSAGE("Found y value " << y << " at row " << i);
double myZ = mySmpModel->data(mySmpModel->index(i, SMP_Z_COLUMN)).toDouble();
if (myZ == z) {
- std::cout << "Found z value " << z << " at row " << i << std::endl;
+ MESSAGE("Found z value " << z << " at row " << i);
return true;
}
}
}
}
- std::cout << "Not found x,y,z values: " << x << " " << y << " " << z << std::endl;
+ MESSAGE("Not found x,y,z values: " << x << " " << y << " " << z);
return false;
}
void GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()
{
- std::cout << "GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()" << std::endl;
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()");
const int row = mySmpModel->rowCount() ;
double x = myXCoord->text().toDouble();
double y = myYCoord->text().toDouble();
mySmpModel->setData(mySmpModel->index(row, SMP_SIZE_COLUMN),size);
mySmpModel->setItem( row, SMP_SIZE_COLUMN, new QStandardItem(QString::number(size,'f')) );
-// std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_X_COLUMN<<")).toDouble(): "
-// << mySmpModel->data(mySmpModel->index(row,SMP_X_COLUMN)).toDouble() << std::endl;
-// std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_Y_COLUMN<<")).toDouble(): "
-// << mySmpModel->data(mySmpModel->index(row,SMP_Y_COLUMN)).toDouble() << std::endl;
-// std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_Z_COLUMN<<")).toDouble(): "
-// << mySmpModel->data(mySmpModel->index(row,SMP_Z_COLUMN)).toDouble() << std::endl;
-// std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_SIZE_COLUMN<<")).toDouble(): "
-// << mySmpModel->data(mySmpModel->index(row,SMP_SIZE_COLUMN)).toDouble() << std::endl;
-
mySizeMapTableView->clearSelection();
mySizeMapTableView->scrollTo( mySmpModel->item( row, SMP_SIZE_COLUMN )->index() );
}
it.toBack();
while ( it.hasPrevious() ) {
row = it.previous();
- cout << "delete row #"<< row <<endl;
+ MESSAGE("delete row #"<< row);
mySmpModel->removeRow(row );
}
mySizeMapTableView->clearSelection();
myOptimizationLevelCombo->setEnabled( !myBoundaryRecoveryCheck->isChecked() );
}
-bool GHS3DPluginGUI_HypothesisCreator::checkParams() const
+bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const
{
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::checkParams");
+
if ( !QFileInfo( myWorkingDir->text().trimmed() ).isWritable() ) {
SUIT_MessageBox::warning( dlg(),
tr( "SMESH_WRN_WARNING" ),
tr( "GHS3D_PERMISSION_DENIED" ) );
return false;
}
+
return true;
}
void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
{
- std::cout << "GHS3DPluginGUI_HypothesisCreator::retrieveParams" << std::endl;
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::retrieveParams");
GHS3DHypothesisData data;
readParamsFromHypo( data );
myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery );
myTextOption ->setText ( data.myTextOption );
- TSizeMapVertexValues::iterator it;
+ TSizeMapVertexValues::const_iterator it;
int row = 0;
for(it = data.mySizeMapVerteces.begin() ; it != data.mySizeMapVerteces.end(); it++ )
{
- double x = it->first->x;
- double y = it->first->y;
- double z = it->first->z;
- double size = it->second;
+ double x = it->at(0);
+ double y = it->at(1);
+ double z = it->at(2);
+ double size = it->at(3);
// SMP_X_COLUMN
mySmpModel->setData(mySmpModel->index(row, SMP_X_COLUMN),x);
mySmpModel->setItem( row, SMP_X_COLUMN, new QStandardItem(QString::number(x)) );
mySmpModel->setData(mySmpModel->index(row, SMP_SIZE_COLUMN),size);
mySmpModel->setItem( row, SMP_SIZE_COLUMN, new QStandardItem(QString::number(size)) );
- std::cout << "Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size << std::endl;
+ MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size);
row++;
}
QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
{
- std::cout << "GHS3DPluginGUI_HypothesisCreator::storeParams" << std::endl;
- GHS3DHypothesisData data;
- readParamsFromWidgets( data );
- storeParamsToHypo( data );
-
- QString valStr = "";
-
- if ( !data.myBoundaryRecovery )
- valStr = "-c " + QString::number( !data.myToMeshHoles );
-
- if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 4 && !data.myBoundaryRecovery) {
- char* level[] = { "none" , "light" , "standard" , "strong" };
- valStr += " -o ";
- valStr += level[ data.myOptimizationLevel ];
- }
- if ( data.myMaximumMemory > 0 ) {
- valStr += " -m ";
- valStr += QString::number( data.myMaximumMemory );
- }
- if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
- valStr += " -M ";
- valStr += QString::number( data.myInitialMemory );
- }
- valStr += " -v ";
- valStr += QString::number( data.myVerboseLevel );
-
- if ( !data.myToCreateNewNodes )
- valStr += " -p0";
-
- if ( data.myBoundaryRecovery )
- valStr += " -C";
-
- valStr += " ";
- valStr += data.myTextOption;
-
- // TODO
- // Add size map parameters storage
-
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParams");
+ GHS3DHypothesisData data;
+ readParamsFromWidgets( data );
+ storeParamsToHypo( data );
+
+ QString valStr = "";
+
+ if ( !data.myBoundaryRecovery )
+ valStr = "-c " + QString::number( !data.myToMeshHoles );
+
+ if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 4 && !data.myBoundaryRecovery) {
+ char* level[] = { "none" , "light" , "standard" , "strong" };
+ valStr += " -o ";
+ valStr += level[ data.myOptimizationLevel ];
+ }
+ if ( data.myMaximumMemory > 0 ) {
+ valStr += " -m ";
+ valStr += QString::number( data.myMaximumMemory );
+ }
+ if ( data.myInitialMemory > 0 && !data.myBoundaryRecovery ) {
+ valStr += " -M ";
+ valStr += QString::number( data.myInitialMemory );
+ }
+ valStr += " -v ";
+ valStr += QString::number( data.myVerboseLevel );
+
+ if ( !data.myToCreateNewNodes )
+ valStr += " -p0";
+
+ if ( data.myBoundaryRecovery )
+ valStr += " -C";
+
+ valStr += " ";
+ valStr += data.myTextOption;
+
+ valStr += " #BEGIN ENFORCED VERTECES#";
+ // Add size map parameters storage
+ for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
+ valStr += " (";
+ double x = mySmpModel->data(mySmpModel->index(i,SMP_X_COLUMN)).toDouble();
+ double y = mySmpModel->data(mySmpModel->index(i,SMP_Y_COLUMN)).toDouble();
+ double z = mySmpModel->data(mySmpModel->index(i,SMP_Z_COLUMN)).toDouble();
+ double size = mySmpModel->data(mySmpModel->index(i,SMP_SIZE_COLUMN)).toDouble();
+ valStr += QString::number( x );
+ valStr += ",";
+ valStr += QString::number( y );
+ valStr += ",";
+ valStr += QString::number( z );
+ valStr += ")=";
+ valStr += QString::number( size );
+ if (i!=mySmpModel->rowCount()-1)
+ valStr += ";";
+ }
+ valStr += " #END ENFORCED VERTECES#";
+ MESSAGE(valStr.toStdString());
return valStr;
}
bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const
{
- std::cout << "GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo" << std::endl;
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo");
GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() );
h_data.myTextOption = h->GetTextOption();
GHS3DPlugin::GHS3DSizeMapVertexList_var verteces = h->GetSizeMapVerteces();
- std::cout << "verteces->length(): " << verteces->length() << std::endl;
+ MESSAGE("verteces->length(): " << verteces->length());
h_data.mySizeMapVerteces.clear();
for (int i=0 ; i<verteces->length() ; i++) {
- GHS3DSizeMapVertex* myVertex = new GHS3DSizeMapVertex;
- myVertex->x = verteces[i].x;
- myVertex->y = verteces[i].y;
- myVertex->z = verteces[i].z;
- double size = verteces[i].size;
- std::cout << "Add enforced vertex ("<< myVertex->x << ","<< myVertex->y << ","<< myVertex->z << ") ="<< size << std::endl;
- h_data.mySizeMapVerteces[myVertex] = size;
+ GHS3DSizeMapVertex myVertex;
+ myVertex.push_back(verteces[i].x);
+ myVertex.push_back(verteces[i].y);
+ myVertex.push_back(verteces[i].z);
+ myVertex.push_back(verteces[i].size);
+ MESSAGE("Add enforced vertex ("<< myVertex[0] << ","<< myVertex[1] << ","<< myVertex[2] << ") ="<< myVertex[3]);
+ h_data.mySizeMapVerteces.push_back(myVertex);
}
return true;
}
bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const
{
- std::cout << "GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo" << std::endl;
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo");
GHS3DPlugin::GHS3DPlugin_Hypothesis_var h =
GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() );
GHS3DPlugin::GHS3DSizeMapVertexList_var vertexHyp = h->GetSizeMapVerteces();
int nbVertexHyp = vertexHyp->length();
- std::cout << "Store params for size maps: " << nbVertex << " enforced verteces" << std::endl;
- std::cout << "h->GetSizeMapVerteces()->length(): " << nbVertexHyp << std::endl;
+ MESSAGE("Store params for size maps: " << nbVertex << " enforced verteces");
+ MESSAGE("h->GetSizeMapVerteces()->length(): " << nbVertexHyp);
// Some verteces were removed
if (nbVertex < nbVertexHyp) {
h->ClearSizeMapVerteces();
else {
// iterate over verteces of hypo
-// GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexHypIt;
for(int i = 0 ; i <nbVertexHyp ; i++) {
-// for(vertexHypIt = vertexHyp.begin() ; vertexHypIt != vertexHyp.end(); vertexHypIt++ ) {
double x = vertexHyp[i].x;
double y = vertexHyp[i].y;
double z = vertexHyp[i].z;
}
}
-// if ((int) h_data.mySizeMapVerteces.size() == 0)
-// if (h->GetSizeMapVerteces()->length() > 0)
-// h->ClearSizeMapVerteces();
-// else
-// h->ClearSizeMapVerteces();
-
TSizeMapVertexValues::const_iterator it;
for(it = h_data.mySizeMapVerteces.begin() ; it != h_data.mySizeMapVerteces.end(); it++ ) {
- double x = it->first->x;
- double y = it->first->y;
- double z = it->first->z;
- double size = it->second;
- std::cout << "(" << x << ", "
+ double x = it->at(0);
+ double y = it->at(1);
+ double z = it->at(2);
+ double size = it->at(3);
+ MESSAGE("(" << x << ", "
<< y << ", "
<< z << ") = "
- << size << std::endl;
+ << size );
double mySize;
try {
mySize = h->GetSizeMapVertex(x,y,z);
- std::cout << "Old size: " << mySize << std::endl;
+ MESSAGE("Old size: " << mySize);
if (mySize != size) {
- std::cout << "Setting new size: " << size << std::endl;
+ MESSAGE("Setting new size: " << size);
h->SetSizeMapVertex(x,y,z,size);
}
}
catch (...) {
- std::cout << "Setting new size: " << size << std::endl;
+ MESSAGE("Setting new size: " << size);
h->SetSizeMapVertex(x,y,z,size);
}
}
bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const
{
- std::cout << "GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets" << std::endl;
+ MESSAGE("GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets");
h_data.myName = myName ? myName->text() : "";
h_data.myToMeshHoles = myToMeshHolesCheck->isChecked();
h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1;
h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
h_data.myTextOption = myTextOption->text();
h_data.mySizeMapVerteces.clear();
+
for (int i=0 ; i<mySmpModel->rowCount() ; i++) {
- GHS3DSizeMapVertex* myVertex = new GHS3DSizeMapVertex;
- myVertex->x = mySmpModel->data(mySmpModel->index(i,SMP_X_COLUMN)).toDouble();
- myVertex->y = mySmpModel->data(mySmpModel->index(i,SMP_Y_COLUMN)).toDouble();
- myVertex->z = mySmpModel->data(mySmpModel->index(i,SMP_Z_COLUMN)).toDouble();
- double size = mySmpModel->data(mySmpModel->index(i,SMP_SIZE_COLUMN)).toDouble();
- std::cout << "Add new enforced vertex (" << myVertex->x << ", "
- << myVertex->y << ", "
- << myVertex->z << ") = "
- << size << std::endl;
- h_data.mySizeMapVerteces[myVertex] = size;
+ GHS3DSizeMapVertex myVertex;
+ myVertex.push_back(mySmpModel->data(mySmpModel->index(i,SMP_X_COLUMN)).toDouble());
+ myVertex.push_back(mySmpModel->data(mySmpModel->index(i,SMP_Y_COLUMN)).toDouble());
+ myVertex.push_back(mySmpModel->data(mySmpModel->index(i,SMP_Z_COLUMN)).toDouble());
+ myVertex.push_back(mySmpModel->data(mySmpModel->index(i,SMP_SIZE_COLUMN)).toDouble());
+ MESSAGE("Add new enforced vertex (" << myVertex[0] << ", "
+ << myVertex[1] << ", "
+ << myVertex[2] << ") = "
+ << myVertex[3]);
+ h_data.mySizeMapVerteces.push_back(myVertex);
}
return true;
#include "GHS3DPlugin_Defs.hxx"
#include <SMESHGUI_Hypotheses.h>
+// #include <SalomeApp_DoubleSpinBox.h>
+
#include <QItemDelegate>
#include <map>
#include <vector>
+#include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm)
class QWidget;
class QComboBox;
class QStandardItem;
class QDoubleValidator;
-typedef struct
-{
- double x;
- double y;
- double z;
-} GHS3DSizeMapVertex;
-typedef std::map<GHS3DSizeMapVertex*,double> TSizeMapVertexValues;
+typedef std::vector<double> GHS3DSizeMapVertex;
+typedef std::vector<GHS3DSizeMapVertex> TSizeMapVertexValues;
typedef struct
{
- bool myToMeshHoles;
- int myMaximumMemory;
- int myInitialMemory;
- int myOptimizationLevel;
- bool myKeepFiles;
- QString myWorkingDir;
- QString myName;
+ bool myToMeshHoles,myKeepFiles,myToCreateNewNodes,myBoundaryRecovery;
+ int myMaximumMemory,myInitialMemory,myOptimizationLevel;
+ QString myName,myWorkingDir,myTextOption;
short myVerboseLevel;
- bool myToCreateNewNodes;
- bool myBoundaryRecovery;
- QString myTextOption;
TSizeMapVertexValues mySizeMapVerteces;
-// QList<GHS3DSizeMapVertex> mySizeMapVerteces;
-
} GHS3DHypothesisData;
/*!
GHS3DPluginGUI_HypothesisCreator( const QString& );
virtual ~GHS3DPluginGUI_HypothesisCreator();
- virtual bool checkParams() const;
+ virtual bool checkParams(QString& msg) const;
virtual QString helpPage() const;
protected: