_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
GeomToolSelected = new GeomSelectionTools(aStudy);
+ aSel = GeomToolSelected->selectionMgr();
+
/* Initialize the Python interpreter */
- assert(Py_IsInitialized());
+ //assert(Py_IsInitialized());
+ if (not Py_IsInitialized())
+ throw ("Erreur: Python interpreter is not initialized");
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyRun_SimpleString("from math import *");
PyGILState_Release(gstate);
+
}
BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
mySizeMapTable->setHorizontalHeaderLabels(sizeMapHeaders);
mySizeMapTable->horizontalHeader()->hideSection( SMP_ENTRY_COLUMN );
mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
- mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
+ mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
mySizeMapTable->setAlternatingRowColors(true);
mySizeMapTable->verticalHeader()->hide();
connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemoveMap()));
connect(mySizeMapTable, SIGNAL(cellChanged ( int, int )),this,SLOT (onSetSizeMap(int,int )));
+// connect(tab, SIGNAL(currentChanged ( int )),this,SLOT (onSetSelectionFilter(int)));
+
return fr;
}
+void BLSURFPluginGUI_HypothesisCreator::onSetSelectionFilter(int page)
+{
+ cout << "BLSURFPluginGUI_HypothesisCreator::onSetSelectionFilter(" << page << ")" << endl;
+ aSel->clearFilters();
+ if (page == SMP_TAB) {
+ cout << "Page is SIZEMAP" << endl;
+ aSel = GeomToolSelected->selectionMgr();
+ }
+}
+
void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
{
cout << "BLSURFPluginGUI_HypothesisCreator::retrieveParams" << endl;
}
mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
- mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
+ mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
// update widgets
that->onPhysicalMeshChanged();
BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
that->myOptions = h->GetOptionValues();
+ that->mySMPMap.clear();
+
+ // classic size maps
+ BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
+ cout << "mySizeMaps->length() = " << mySizeMaps->length() << endl;
+
+ for ( int i = 0;i<mySizeMaps->length(); ++i ) {
+ QString fullSizeMaps = mySizeMaps[i].in();
+ QStringList fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
+ if ( fullSizeMapList.count() > 1 ) {
+ string fullSizeMap = fullSizeMapList[1].toStdString();
+ int pos = fullSizeMap.find("return")+7;
+ QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
+ that->mySMPMap[fullSizeMapList[0]] = sizeMap;
+ that->mySMPShapeTypeMap[fullSizeMapList[0]] = GeomToolSelected->entryToShape(fullSizeMapList[0].toStdString()).ShapeType();
+ MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
+ MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
+ }
+ }
- BLSURFPlugin::string_array_var mySMPString = h->GetSizeMapEntries();
-
- cout << "mySMPString->length() = " << mySMPString->length() << endl;
- that->mySMPMap.clear();
-
- TopoDS_Shape S;
-
- for ( int i = 0;i<mySMPString->length(); ++i ) {
- QString sizemaps_line = mySMPString[i].in();
- QStringList entry_sm = sizemaps_line.split( "|", QString::KeepEmptyParts );
- if ( entry_sm.count() > 1 ) {
- string fullSizeMap = entry_sm[1].toStdString();
- int pos = fullSizeMap.find("return")+7;
- QString sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
- that->mySMPMap[entry_sm[0]] = sizeMap;
- that->mySMPShapeTypeMap[entry_sm[0]] = GeomToolSelected->entryToShape(entry_sm[0].toStdString()).ShapeType();
- MESSAGE("mySMPMap[" << entry_sm[0].toStdString() << "] = " << sizeMap.toStdString());
- MESSAGE("mySMPShapeTypeMap[" << entry_sm[0].toStdString() << "] = " << that->mySMPShapeTypeMap[entry_sm[0]]);
- }
+ // custom size maps
+/*
+ BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
+ cout << "myCustomSizeMaps->length() = " << myCustomSizeMaps->length() << endl;
+
+ for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
+ QString fullCustomSizeMaps = myCustomSizeMaps[i].in();
+ QStringList fullCustomSizeMapList = fullCustomSizeMaps.split( "|", QString::KeepEmptyParts );
+ if ( fullCustomSizeMapList.count() > 1 ) {
+ that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
+ that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShape(fullCustomSizeMapList[0].toStdString()).ShapeType();
+ MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
+ MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
}
+ }
+*/
+ // attractor
+ BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
+ cout << "myAttractors->length() = " << allMyAttractors->length() << endl;
+
+ for ( int i = 0;i<allMyAttractors->length(); ++i ) {
+ QString myAttractors = allMyAttractors[i].in();
+ QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
+ if ( myAttractorList.count() > 1 ) {
+ that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
+ that->mySMPShapeTypeMap[myAttractorList[0]] = GeomToolSelected->entryToShape(myAttractorList[0].toStdString()).ShapeType();
+ MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
+ MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
+ }
+ }
return true;
}
h->SetOptionValues( myOptions ); // is set in checkParams()
BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
- //printf("storeParamsToHypo():that->mySMPMap.size()=%d\n",that->mySMPMap.size());
QMapIterator<QString,QString> i(that->mySMPMap);
- // Reset the size maps in engine
- // h->ClearSizeMaps();
// Iterate over each size map
while (i.hasNext()) {
i.next();
const QString entry = i.key();
const QString sizeMap = i.value();
+/*
+ if (not that->sizeMapValidationFromEntry(entry,false)) {
+ cout << "Size map for entry " << entry.toStdString() << " is not valid" << endl;
+ ok = false;
+ continue;
+ }
+*/
if (sizeMap == "__TO_DELETE__") {
cout << "Delete entry " << entry.toStdString() << " from engine" << endl;
h->UnsetEntry(entry.toLatin1().constData());
- ok = false;
- break;
}
-
- QString fullSizeMap;
- fullSizeMap = QString("");
- if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
- fullSizeMap = QString("def f(u,v): return ") + sizeMap;
- else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
- fullSizeMap = QString("def f(t): return ") + sizeMap;
- else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
- fullSizeMap = QString("def f(): return ") + sizeMap;
-
- cout << "SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString() << endl;
- h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
+ else if (sizeMap.startsWith("ATTRACTOR")) {
+ cout << "SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString() << endl;
+ h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
+ }
+ else if (sizeMap.startsWith("def")) {
+ cout << "SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString() << endl;
+// h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
+ }
+ else {
+ QString fullSizeMap;
+ fullSizeMap = QString("");
+ if (that->mySMPShapeTypeMap[entry] == TopAbs_FACE)
+ fullSizeMap = QString("def f(u,v): return ") + sizeMap;
+ else if (that->mySMPShapeTypeMap[entry] == TopAbs_EDGE)
+ fullSizeMap = QString("def f(t): return ") + sizeMap;
+ else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
+ fullSizeMap = QString("def f(): return ") + sizeMap;
+
+ cout << "SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString() << endl;
+ h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
+ }
}
}
catch(const SALOME::SALOME_Exception& ex)
mySizeMapTable->removeRow(row );
}
mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
- mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
+ mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
}
void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(int row,int col)
{
- cout<<"BLSURFPluginGUI_HypothesisCreator::onSetSizeMap()"<<endl;
+ cout<<"BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< row << "," << col << ")"<<endl;
if (col == SMP_SIZEMAP_COLUMN) {
BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
QString entry = that->mySizeMapTable->item(row, SMP_ENTRY_COLUMN)->text();
QString sizeMap = that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->text().trimmed();
+ cout << "entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString() << endl;
if (not that->mySMPShapeTypeMap.contains(entry))
return;
- QString prevSizeMap = that->mySMPMap[entry];
- that->mySMPMap[entry] = sizeMap;
- if (not sizeMapValidationFromEntry(entry)) {
- that->mySMPMap[entry] = prevSizeMap;
- that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(prevSizeMap);
+ if (that->mySMPMap.contains(entry))
+ if (that->mySMPMap[entry] == sizeMap)
+ return;
+ QColor* bgColor = new QColor("white");
+ QColor* fgColor = new QColor("black");
+ if (not sizeMap.isEmpty()) {
+ that->mySMPMap[entry] = sizeMap;
+ if (not sizeMapValidationFromRow(row)) {
+ bgColor->setRgb(255,0,0);
+ fgColor->setRgb(255,255,255);
+ }
}
+ else {
+ cout << "Size map empty: reverse to precedent value" << endl;
+ that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setText(that->mySMPMap[entry]);
+ }
+ that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setBackground(QBrush(*bgColor));
+ that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setBackground(QBrush(*bgColor));
+ that->mySizeMapTable->item(row, SMP_NAME_COLUMN)->setForeground(QBrush(*fgColor));
+ that->mySizeMapTable->item(row, SMP_SIZEMAP_COLUMN)->setForeground(QBrush(*fgColor));
+ mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
}
}
TopoDS_Shape S;
string entry, shapeName;
- LightApp_SelectionMgr* aSel = GeomToolSelected->selectionMgr();
+// LightApp_SelectionMgr* aSel = GeomToolSelected->selectionMgr();
+
SALOME_ListIO ListSelectedObjects;
aSel->selectedObjects(ListSelectedObjects, NULL, false );
if (!ListSelectedObjects.IsEmpty())
mySizeMapTable->setItem( row, SMP_SIZEMAP_COLUMN, new QTableWidgetItem( sizeMap ) );
mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN )->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable |Qt::ItemIsEnabled );
mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
- mySizeMapTable->resizeColumnToContents(SMP_ENTRY_COLUMN);
+ mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
mySizeMapTable->clearSelection();
mySizeMapTable->scrollToItem( mySizeMapTable->item( row, SMP_SIZEMAP_COLUMN ) );
return true;
}
-bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow)
+bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
{
cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow()"<<endl;
QString myEntry = mySizeMapTable->item( myRow, SMP_ENTRY_COLUMN )->text();
- return sizeMapValidationFromEntry(myEntry);
+ bool res = sizeMapValidationFromEntry(myEntry,displayError);
+ mySizeMapTable->setFocus();
+ return res;
}
-bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry)
+bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
{
cout<<"BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()"<<endl;
string expr;
- if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
- expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
- else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
- expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
- else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
- expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
+ if (that->mySMPMap[myEntry].startsWith("def")) {
+ cout << "custom function" << endl;
+ expr = that->mySMPMap[myEntry].toStdString();
+ }
+ else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
+ cout << "Attractor" << endl;
+// if ((that->mySMPMap[myEntry].count(QRegExp("ATTRACTOR([0-9])")) != 1))
+ if ((that->mySMPMap[myEntry].count('(') != 1) or
+ (that->mySMPMap[myEntry].count(')') != 1) or
+ (that->mySMPMap[myEntry].count(';') != 4) or
+ (that->mySMPMap[myEntry].size() == 15)){
+ if (displayError)
+ SUIT_MessageBox::warning( dlg(),"Definition of attractor : Error" ,"An attractor is defined with the following pattern: ATTRACTOR(xa;ya;za;a;b)" );
+ return false;
+ }
+ return true;
+ }
+ else {
+ // case size map is empty
+ if (that->mySMPMap[myEntry].isEmpty()) {
+ if (displayError)
+ SUIT_MessageBox::warning( dlg(),"Definition of size map : Error" , "Size map can't be empty");
+ return false;
+ }
- assert(Py_IsInitialized());
+ if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_FACE)
+ expr = "def f(u,v) : return " + that->mySMPMap[myEntry].toStdString();
+ else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_EDGE)
+ expr = "def f(t) : return " + that->mySMPMap[myEntry].toStdString();
+ else if ( that->mySMPShapeTypeMap[myEntry] == TopAbs_VERTEX)
+ expr = "def f() : return " + that->mySMPMap[myEntry].toStdString();
+ }
+ //assert(Py_IsInitialized());
+ if (not Py_IsInitialized())
+ throw ("Erreur: Python interpreter is not initialized");
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyErr_Print();
PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
Py_DECREF(new_stderr);
- SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
+ if (displayError)
+ SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
PyGILState_Release(gstate);
return false;
}
PyErr_Print();
PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
Py_DECREF(new_stderr);
- SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
+ if (displayError)
+ SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
PyGILState_Release(gstate);
return false;
}