Mod/Mesh/Gui/Command.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # ifdef FC_OS_WIN32
00027 # include <windows.h>
00028 # endif
00029 # include <qaction.h>
00030 # include <qdir.h>
00031 # include <qfileinfo.h>
00032 # include <qinputdialog.h>
00033 # include <qmessagebox.h>
00034 # include <qstringlist.h>
00035 //# include <gts.h>
00036 # include <map>
00037 #endif
00038 
00039 #ifndef __InventorAll__
00040 # include <Gui/InventorAll.h>
00041 #endif
00042 
00043 #include <Mod/Mesh/App/Core/Smoothing.h>
00044 #include <Mod/Mesh/App/MeshFeature.h>
00045 #include <Mod/Mesh/App/FeatureMeshCurvature.h>
00046 
00047 #include <Base/Console.h>
00048 #include <Base/Exception.h>
00049 #include <App/Document.h>
00050 #include <App/DocumentObjectGroup.h>
00051 #include <App/DocumentObject.h>
00052 #include <Gui/Application.h>
00053 #include <Gui/BitmapFactory.h>
00054 #include <Gui/MainWindow.h>
00055 #include <Gui/Command.h>
00056 #include <Gui/Control.h>
00057 #include <Gui/Document.h>
00058 #include <Gui/FileDialog.h>
00059 #include <Gui/Selection.h>
00060 #include <Gui/ViewProvider.h>
00061 #include <Gui/View3DInventor.h>
00062 #include <Gui/View3DInventorViewer.h>
00063 #include <Gui/WaitCursor.h>
00064 
00065 #include "DlgEvaluateMeshImp.h"
00066 #include "DlgRegularSolidImp.h"
00067 #include "RemoveComponents.h"
00068 #include "DlgSmoothing.h"
00069 #include "ViewProviderMeshFaceSet.h"
00070 #include "ViewProviderCurvature.h"
00071 #include "MeshEditor.h"
00072 
00073 using namespace Mesh;
00074 
00075 
00076 DEF_STD_CMD_A(CmdMeshTransform);
00077 
00078 CmdMeshTransform::CmdMeshTransform()
00079   :Command("Mesh_Transform")
00080 {
00081   sAppModule    = "Mesh";
00082   sGroup        = QT_TR_NOOP("Mesh");
00083   sMenuText     = QT_TR_NOOP("Transform mesh");
00084   sToolTipText  = QT_TR_NOOP("Rotate or move a mesh");
00085   sWhatsThis    = "Mesh_Transform";
00086   sStatusTip    = QT_TR_NOOP("Rotate or move a mesh");
00087   sPixmap       = "Std_Tool1";
00088 }
00089 
00090 void CmdMeshTransform::activated(int iMsg)
00091 {
00092   unsigned int n = getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId());
00093   if ( n!=1 ) return;
00094 
00095   std::string fName = getUniqueObjectName("Move");
00096   std::vector<Gui::SelectionSingleton::SelObj> cSel = getSelection().getSelection();
00097 
00098   openCommand("Mesh Mesh Create");
00099   doCommand(Doc,"App.activeDocument().addObject(\"Mesh::Transform\",\"%s\")",fName.c_str());
00100   doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",fName.c_str(),cSel[0].FeatName);
00101   doCommand(Gui,"Gui.hide(\"%s\")",cSel[0].FeatName);
00102   commitCommand(); 
00103  
00104   updateActive();
00105 }
00106 
00107 bool CmdMeshTransform::isActive(void)
00108 {
00109   //return true;
00110   return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1;
00111 }
00112 
00113 //--------------------------------------------------------------------------------------
00114 
00115 DEF_STD_CMD_A(CmdMeshDemolding);
00116 
00117 CmdMeshDemolding::CmdMeshDemolding()
00118   :Command("Mesh_Demolding")
00119 {
00120   sAppModule    = "Mesh";
00121   sGroup        = QT_TR_NOOP("Mesh");
00122   sMenuText     = QT_TR_NOOP("Interactive demolding direction");
00123   sToolTipText  = sMenuText;
00124   sWhatsThis    = "Mesh_Demolding";
00125   sStatusTip    = sMenuText;
00126   sPixmap       = "Std_Tool1";
00127 }
00128 
00129 void CmdMeshDemolding::activated(int iMsg)
00130 {
00131   unsigned int n = getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId());
00132   if ( n!=1 ) return;
00133 
00134   std::string fName = getUniqueObjectName("Demolding");
00135   std::vector<Gui::SelectionSingleton::SelObj> cSel = getSelection().getSelection();
00136 
00137   openCommand("Mesh Mesh Create");
00138   doCommand(Doc,"App.activeDocument().addObject(\"Mesh::TransformDemolding\",\"%s\")",fName.c_str());
00139   doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",fName.c_str(),cSel[0].FeatName);
00140   doCommand(Gui,"Gui.hide(\"%s\")",cSel[0].FeatName);
00141   commitCommand(); 
00142  
00143   updateActive();
00144 }
00145 
00146 bool CmdMeshDemolding::isActive(void)
00147 {
00148   //return true;
00149   return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1;
00150 }
00151 
00152 //--------------------------------------------------------------------------------------
00153 
00154 DEF_STD_CMD_A(CmdMeshUnion);
00155 
00156 CmdMeshUnion::CmdMeshUnion()
00157   :Command("Mesh_Union")
00158 {
00159     sAppModule    = "Mesh";
00160     sGroup        = QT_TR_NOOP("Mesh");
00161     sMenuText     = QT_TR_NOOP("Union");
00162     sToolTipText  = sMenuText;
00163     sWhatsThis    = "Mesh_Union";
00164     sStatusTip    = sMenuText;
00165 }
00166 
00167 void CmdMeshUnion::activated(int iMsg)
00168 {
00169     std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00170     std::string name1 = obj.front()->getNameInDocument();
00171     std::string name2 = obj.back()->getNameInDocument();
00172     std::string name3 = getUniqueObjectName("Union");
00173     openCommand("Mesh Union");
00174     doCommand(Doc,
00175         "import Mesh,MeshGui\n"
00176         "mesh = App.ActiveDocument.%s.Mesh."
00177         "unite(App.ActiveDocument.%s.Mesh)\n"
00178         "App.activeDocument().addObject(\"Mesh::Feature\",\"%s\")\n"
00179         "App.activeDocument().%s.Mesh = mesh\n",
00180         name1.c_str(), name2.c_str(),
00181         name3.c_str(), name3.c_str());
00182  
00183     updateActive();
00184     commitCommand();
00185 }
00186 
00187 bool CmdMeshUnion::isActive(void)
00188 {
00189     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2;
00190 }
00191 
00192 //--------------------------------------------------------------------------------------
00193 
00194 DEF_STD_CMD_A(CmdMeshDifference);
00195 
00196 CmdMeshDifference::CmdMeshDifference()
00197   :Command("Mesh_Difference")
00198 {
00199     sAppModule    = "Mesh";
00200     sGroup        = QT_TR_NOOP("Mesh");
00201     sMenuText     = QT_TR_NOOP("Difference");
00202     sToolTipText  = sMenuText;
00203     sWhatsThis    = "Mesh_Difference";
00204     sStatusTip    = sMenuText;
00205 }
00206 
00207 void CmdMeshDifference::activated(int iMsg)
00208 {
00209     std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00210     std::string name1 = obj.front()->getNameInDocument();
00211     std::string name2 = obj.back()->getNameInDocument();
00212     std::string name3 = getUniqueObjectName("Difference");
00213     openCommand("Mesh Union");
00214     doCommand(Doc,
00215         "import Mesh,MeshGui\n"
00216         "mesh = App.ActiveDocument.%s.Mesh."
00217         "difference(App.ActiveDocument.%s.Mesh)\n"
00218         "App.activeDocument().addObject(\"Mesh::Feature\",\"%s\")\n"
00219         "App.activeDocument().%s.Mesh = mesh\n",
00220         name1.c_str(), name2.c_str(),
00221         name3.c_str(), name3.c_str());
00222 
00223     updateActive();
00224     commitCommand();
00225 }
00226 
00227 bool CmdMeshDifference::isActive(void)
00228 {
00229     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2;
00230 }
00231 
00232 //--------------------------------------------------------------------------------------
00233 
00234 DEF_STD_CMD_A(CmdMeshIntersection);
00235 
00236 CmdMeshIntersection::CmdMeshIntersection()
00237   :Command("Mesh_Intersection")
00238 {
00239     sAppModule    = "Mesh";
00240     sGroup        = QT_TR_NOOP("Mesh");
00241     sMenuText     = QT_TR_NOOP("Intersection");
00242     sToolTipText  = sMenuText;
00243     sWhatsThis    = "Mesh_Intersection";
00244     sStatusTip    = sMenuText;
00245 }
00246 
00247 void CmdMeshIntersection::activated(int iMsg)
00248 {
00249     std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00250     std::string name1 = obj.front()->getNameInDocument();
00251     std::string name2 = obj.back()->getNameInDocument();
00252     std::string name3 = getUniqueObjectName("Intersection");
00253     openCommand("Mesh Union");
00254     doCommand(Doc,
00255         "import Mesh,MeshGui\n"
00256         "mesh = App.ActiveDocument.%s.Mesh."
00257         "intersect(App.ActiveDocument.%s.Mesh)\n"
00258         "App.activeDocument().addObject(\"Mesh::Feature\",\"%s\")\n"
00259         "App.activeDocument().%s.Mesh = mesh\n",
00260         name1.c_str(), name2.c_str(),
00261         name3.c_str(), name3.c_str());
00262 
00263     updateActive();
00264     commitCommand();
00265 }
00266 
00267 bool CmdMeshIntersection::isActive(void)
00268 {
00269     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2;
00270 }
00271 
00272 //--------------------------------------------------------------------------------------
00273 
00274 DEF_STD_CMD_A(CmdMeshImport);
00275 
00276 CmdMeshImport::CmdMeshImport()
00277   :Command("Mesh_Import")
00278 {
00279     sAppModule    = "Mesh";
00280     sGroup        = QT_TR_NOOP("Mesh");
00281     sMenuText     = QT_TR_NOOP("Import mesh...");
00282     sToolTipText  = QT_TR_NOOP("Imports a mesh from file");
00283     sWhatsThis    = "Mesh_Import";
00284     sStatusTip    = QT_TR_NOOP("Imports a mesh from file");
00285     sPixmap       = "import_mesh";
00286 }
00287 
00288 void CmdMeshImport::activated(int iMsg)
00289 {
00290     // use current path as default
00291     QStringList filter;
00292     filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj *.ply)");
00293     filter << QObject::tr("Binary STL (*.stl)");
00294     filter << QObject::tr("ASCII STL (*.ast)");
00295     filter << QObject::tr("Binary Mesh (*.bms)");
00296     filter << QObject::tr("Alias Mesh (*.obj)");
00297     filter << QObject::tr("Inventor V2.1 ascii (*.iv)");
00298     filter << QObject::tr("Stanford Polygon (*.ply)");
00299     //filter << "Nastran (*.nas *.bdf)";
00300     filter << QObject::tr("All Files (*.*)");
00301 
00302     // Allow multi selection
00303     QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(),
00304         QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));
00305     for (QStringList::Iterator it = fn.begin(); it != fn.end(); ++it) {
00306         QFileInfo fi;
00307         fi.setFile(*it);
00308 
00309         openCommand("Import Mesh");
00310         doCommand(Doc,"import Mesh");
00311         doCommand(Doc,"Mesh.insert(\"%s\")",
00312                  (const char*)(*it).toUtf8());
00313         commitCommand();
00314         updateActive();
00315     }
00316 }
00317 
00318 bool CmdMeshImport::isActive(void)
00319 {
00320     return (getActiveGuiDocument() ? true : false);
00321 }
00322 
00323 //--------------------------------------------------------------------------------------
00324 
00325 DEF_STD_CMD_A(CmdMeshExport);
00326 
00327 CmdMeshExport::CmdMeshExport()
00328   :Command("Mesh_Export")
00329 {
00330     sAppModule    = "Mesh";
00331     sGroup        = QT_TR_NOOP("Mesh");
00332     sMenuText     = QT_TR_NOOP("Export mesh...");
00333     sToolTipText  = QT_TR_NOOP("Exports a mesh to file");
00334     sWhatsThis    = "Mesh_Export";
00335     sStatusTip    = QT_TR_NOOP("Exports a mesh to file");
00336     sPixmap       = "export_mesh";
00337 }
00338 
00339 void CmdMeshExport::activated(int iMsg)
00340 {
00341     std::vector<App::DocumentObject*> docObjs = Gui::Selection().getObjectsOfType
00342         (Mesh::Feature::getClassTypeId());
00343     if (docObjs.size() != 1)
00344         return;
00345 
00346     App::DocumentObject* docObj = docObjs.front();
00347 
00348     QString dir = QString::fromUtf8(docObj->Label.getValue());
00349     QList<QPair<QString, QByteArray> > ext;
00350     ext << qMakePair<QString, QByteArray>(QObject::tr("Binary STL (*.stl)"), "STL");
00351     ext << qMakePair<QString, QByteArray>(QObject::tr("ASCII STL (*.stl)"), "AST");
00352     ext << qMakePair<QString, QByteArray>(QObject::tr("ASCII STL (*.ast)"), "AST");
00353     ext << qMakePair<QString, QByteArray>(QObject::tr("Binary Mesh (*.bms)"), "BMS");
00354     ext << qMakePair<QString, QByteArray>(QObject::tr("Alias Mesh (*.obj)"), "OBJ");
00355     ext << qMakePair<QString, QByteArray>(QObject::tr("Object File Format (*.off)"), "OFF");
00356     ext << qMakePair<QString, QByteArray>(QObject::tr("Inventor V2.1 ascii (*.iv)"), "IV");
00357     ext << qMakePair<QString, QByteArray>(QObject::tr("Standford Polygon (*.ply)"), "PLY");
00358     ext << qMakePair<QString, QByteArray>(QObject::tr("VRML V2.0 (*.wrl *.vrml)"), "VRML");
00359     ext << qMakePair<QString, QByteArray>(QObject::tr("Compressed VRML 2.0 (*.wrz)"), "WRZ");
00360     ext << qMakePair<QString, QByteArray>(QObject::tr("Nastran (*.nas *.bdf)"), "NAS");
00361     ext << qMakePair<QString, QByteArray>(QObject::tr("Python module def (*.py)"), "PY");
00362     ext << qMakePair<QString, QByteArray>(QObject::tr("All Files (*.*)"), ""); // Undefined
00363     QStringList filter;
00364     for (QList<QPair<QString, QByteArray> >::iterator it = ext.begin(); it != ext.end(); ++it)
00365         filter << it->first;
00366 
00367     QString format;
00368     QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
00369         QObject::tr("Export mesh"), dir, filter.join(QLatin1String(";;")), &format);
00370     if (!fn.isEmpty()) {
00371         QFileInfo fi(fn);
00372         QByteArray extension = fi.suffix().toAscii();
00373         for (QList<QPair<QString, QByteArray> >::iterator it = ext.begin(); it != ext.end(); ++it) {
00374             if (it->first == format) {
00375                 extension = it->second;
00376                 break;
00377             }
00378         }
00379 
00380         //openCommand("Export Mesh");
00381         doCommand(Doc,"FreeCAD.ActiveDocument.getObject(\"%s\").Mesh.write(\"%s\",\"%s\")",
00382                  docObj->getNameInDocument(),
00383                  (const char*)fn.toUtf8(),
00384                  (const char*)extension);
00385         //commitCommand();
00386     }
00387 }
00388 
00389 bool CmdMeshExport::isActive(void)
00390 {
00391     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1;
00392 }
00393 
00394 //--------------------------------------------------------------------------------------
00395 
00396 DEF_STD_CMD_A(CmdMeshFromGeometry);
00397 
00398 CmdMeshFromGeometry::CmdMeshFromGeometry()
00399   :Command("Mesh_FromGeometry")
00400 {
00401     sAppModule    = "Mesh";
00402     sGroup        = QT_TR_NOOP("Mesh");
00403     sMenuText     = QT_TR_NOOP("Create mesh from geometry...");
00404     sToolTipText  = QT_TR_NOOP("Create mesh from the selected geometry");
00405     sWhatsThis    = "Mesh_FromGeometry";
00406     sStatusTip    = QT_TR_NOOP("Create mesh from the selected geometry");
00407 }
00408 
00409 void CmdMeshFromGeometry::activated(int iMsg)
00410 {
00411     bool ok;
00412     double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Meshing Tolerance"),
00413         QObject::tr("Enter tolerance for meshing geometry:"), 0.1, 0.01,10.0,2,&ok);
00414     if (!ok)
00415         return;
00416 
00417     App::Document* doc = App::GetApplication().getActiveDocument();
00418     std::vector<App::DocumentObject*> geo = Gui::Selection().getObjectsOfType(App::GeoFeature::getClassTypeId());
00419     for (std::vector<App::DocumentObject*>::iterator it = geo.begin(); it != geo.end(); ++it) {
00420         if (!(*it)->getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) {
00421             // exclude meshes
00422             std::map<std::string, App::Property*> Map;
00423             (*it)->getPropertyMap(Map);
00424             Mesh::MeshObject mesh;
00425             for (std::map<std::string, App::Property*>::iterator jt = Map.begin(); jt != Map.end(); ++jt) {
00426                 if (jt->second->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) {
00427                     std::vector<Base::Vector3d> aPoints;
00428                     std::vector<Data::ComplexGeoData::Facet> aTopo;
00429                     static_cast<App::PropertyComplexGeoData*>(jt->second)->getFaces(aPoints, aTopo,(float)tol);
00430                     mesh.setFacets(aTopo, aPoints);
00431                 }
00432             }
00433 
00434             // create a mesh feature and assign the mesh
00435             Mesh::Feature* mf = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
00436             mf->Mesh.setValue(mesh.getKernel());
00437         }
00438     }
00439 }
00440 
00441 bool CmdMeshFromGeometry::isActive(void)
00442 {
00443     App::Document* doc = App::GetApplication().getActiveDocument();
00444     if (!doc) return false;
00445     return getSelection().countObjectsOfType(App::GeoFeature::getClassTypeId()) >= 1;
00446 }
00447 
00448 //--------------------------------------------------------------------------------------
00449 
00450 DEF_STD_CMD_A(CmdMeshVertexCurvature);
00451 
00452 CmdMeshVertexCurvature::CmdMeshVertexCurvature()
00453   : Command("Mesh_VertexCurvature")
00454 {
00455     sAppModule    = "Mesh";
00456     sGroup        = QT_TR_NOOP("Mesh");
00457     sMenuText     = QT_TR_NOOP("Curvature plot");
00458     sToolTipText  = QT_TR_NOOP("Calculates the curvature of the vertices of a mesh");
00459     sWhatsThis    = "Mesh_VertexCurvature";
00460     sStatusTip    = QT_TR_NOOP("Calculates the curvature of the vertices of a mesh");
00461     sPixmap       = "curv_info";
00462 }
00463 
00464 void CmdMeshVertexCurvature::activated(int iMsg)
00465 {
00466     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00467     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
00468         std::string fName = (*it)->getNameInDocument();
00469         fName += "_Curvature";
00470         fName = getUniqueObjectName(fName.c_str());
00471 
00472         openCommand("Mesh VertexCurvature");
00473         App::DocumentObjectGroup* grp = App::DocumentObjectGroup::getGroupOfObject( *it );
00474         if (grp)
00475             doCommand(Doc,"App.activeDocument().getObject(\"%s\").newObject(\"Mesh::Curvature\",\"%s\")",grp->getNameInDocument(), fName.c_str());
00476         else
00477             doCommand(Doc,"App.activeDocument().addObject(\"Mesh::Curvature\",\"%s\")",fName.c_str());
00478         doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",fName.c_str(),(*it)->getNameInDocument());
00479     }
00480 
00481     commitCommand();
00482     updateActive();
00483 }
00484 
00485 bool CmdMeshVertexCurvature::isActive(void)
00486 {
00487     // Check for the selected mesh feature (all Mesh types)
00488     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0;
00489 }
00490 
00491 //--------------------------------------------------------------------------------------
00492 
00493 DEF_STD_CMD_A(CmdMeshVertexCurvatureInfo);
00494 
00495 CmdMeshVertexCurvatureInfo::CmdMeshVertexCurvatureInfo()
00496   :Command("Mesh_CurvatureInfo")
00497 {
00498     sAppModule    = "Mesh";
00499     sGroup        = QT_TR_NOOP("Mesh");
00500     sMenuText     = QT_TR_NOOP("Curvature info");
00501     sToolTipText  = QT_TR_NOOP("Information about curvature");
00502     sWhatsThis    = "Mesh_CurvatureInfo";
00503     sStatusTip    = QT_TR_NOOP("Information about curvature");
00504 }
00505 
00506 void CmdMeshVertexCurvatureInfo::activated(int iMsg)
00507 {
00508     Gui::Document* doc = Gui::Application::Instance->activeDocument();
00509     Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
00510     if (view) {
00511         Gui::View3DInventorViewer* viewer = view->getViewer();
00512         viewer->setEditing(true);
00513         viewer->setRedirectToSceneGraph(true);
00514         viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_pipette"),4,29));
00515         viewer->addEventCallback(SoEvent::getClassTypeId(),
00516             MeshGui::ViewProviderMeshCurvature::curvatureInfoCallback);
00517      }
00518 }
00519 
00520 bool CmdMeshVertexCurvatureInfo::isActive(void)
00521 {
00522     App::Document* doc = App::GetApplication().getActiveDocument();
00523     if (!doc || doc->countObjectsOfType(Mesh::Curvature::getClassTypeId()) == 0)
00524         return false;
00525 
00526     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00527     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00528         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00529         return !viewer->isEditing();
00530     }
00531 
00532     return false;
00533 }
00534 
00535 //--------------------------------------------------------------------------------------
00536 
00537 DEF_STD_CMD_A(CmdMeshPolySegm);
00538 
00539 CmdMeshPolySegm::CmdMeshPolySegm()
00540   :Command("Mesh_PolySegm")
00541 {
00542     sAppModule    = "Mesh";
00543     sGroup        = QT_TR_NOOP("Mesh");
00544     sMenuText     = QT_TR_NOOP("Make segment");
00545     sToolTipText  = QT_TR_NOOP("Creates a mesh segment");
00546     sWhatsThis    = "Mesh_PolySegm";
00547     sStatusTip    = QT_TR_NOOP("Creates a mesh segment");
00548     sPixmap       = "PolygonPick";
00549 }
00550 
00551 void CmdMeshPolySegm::activated(int iMsg)
00552 {
00553     std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00554     for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
00555         if (it == docObj.begin()) {
00556             Gui::Document* doc = getActiveGuiDocument();
00557             Gui::MDIView* view = doc->getActiveView();
00558             if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00559                 Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
00560                 viewer->setEditing(true);
00561                 viewer->startSelection(Gui::View3DInventorViewer::Clip);
00562                 viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::segmMeshCallback);
00563             }
00564             else {
00565                 return;
00566             }
00567         }
00568 
00569         Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it);
00570         if (pVP->isVisible())
00571             pVP->startEditing();
00572     }
00573 }
00574 
00575 bool CmdMeshPolySegm::isActive(void)
00576 {
00577     // Check for the selected mesh feature (all Mesh types)
00578     if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
00579         return false;
00580 
00581     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00582     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00583         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00584         return !viewer->isEditing();
00585     }
00586 
00587     return false;
00588 }
00589 
00590 //--------------------------------------------------------------------------------------
00591 
00592 DEF_STD_CMD_A(CmdMeshPolySelect);
00593 
00594 CmdMeshPolySelect::CmdMeshPolySelect()
00595   : Command("Mesh_PolySelect")
00596 {
00597     sAppModule    = "Mesh";
00598     sGroup        = QT_TR_NOOP("Mesh");
00599     sMenuText     = QT_TR_NOOP("Select mesh");
00600     sToolTipText  = QT_TR_NOOP("Select an area of the mesh");
00601     sWhatsThis    = "Mesh_PolySelect";
00602     sStatusTip    = QT_TR_NOOP("Select an area of the mesh");
00603 }
00604 
00605 void CmdMeshPolySelect::activated(int iMsg)
00606 {
00607     std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00608     for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
00609         if (it == docObj.begin()) {
00610             Gui::Document* doc = getActiveGuiDocument();
00611             Gui::MDIView* view = doc->getActiveView();
00612             if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00613                 Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
00614                 viewer->setEditing(true);
00615                 viewer->startSelection(Gui::View3DInventorViewer::Rectangle);
00616                 viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::selectGLCallback);
00617             }
00618             else {
00619                 return;
00620             }
00621         }
00622 
00623         Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it);
00624         pVP->startEditing();
00625     }
00626 }
00627 
00628 bool CmdMeshPolySelect::isActive(void)
00629 {
00630     // Check for the selected mesh feature (all Mesh types)
00631     if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
00632         return false;
00633 
00634     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00635     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00636         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00637         return !viewer->isEditing();
00638     }
00639 
00640     return false;
00641 }
00642 
00643 //--------------------------------------------------------------------------------------
00644 
00645 DEF_STD_CMD_A(CmdMeshAddFacet);
00646 
00647 CmdMeshAddFacet::CmdMeshAddFacet()
00648   : Command("Mesh_AddFacet")
00649 {
00650     sAppModule    = "Mesh";
00651     sGroup        = QT_TR_NOOP("Mesh");
00652     sMenuText     = QT_TR_NOOP("Add triangle");
00653     sToolTipText  = QT_TR_NOOP("Add triangle manually to a mesh");
00654     sWhatsThis    = "Mesh_AddFacet";
00655     sStatusTip    = QT_TR_NOOP("Add triangle manually to a mesh");
00656 }
00657 
00658 void CmdMeshAddFacet::activated(int iMsg)
00659 {
00660     std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00661     for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
00662         Gui::Document* doc = Gui::Application::Instance->getDocument((*it)->getDocument());
00663         Gui::MDIView* view = doc->getActiveView();
00664         if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00665             MeshGui::MeshFaceAddition* edit = new MeshGui::MeshFaceAddition
00666                 (static_cast<Gui::View3DInventor*>(view));
00667             edit->startEditing(static_cast<MeshGui::ViewProviderMesh*>
00668                 (Gui::Application::Instance->getViewProvider(*it)));
00669             break;
00670         }
00671     }
00672 }
00673 
00674 bool CmdMeshAddFacet::isActive(void)
00675 {
00676     // Check for the selected mesh feature (all Mesh types)
00677     if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1)
00678         return false;
00679 
00680     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00681     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00682         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00683         return !viewer->isEditing();
00684     }
00685 
00686     return false;
00687 }
00688 
00689 //--------------------------------------------------------------------------------------
00690 
00691 DEF_STD_CMD_A(CmdMeshPolyCut);
00692 
00693 CmdMeshPolyCut::CmdMeshPolyCut()
00694   : Command("Mesh_PolyCut")
00695 {
00696     sAppModule    = "Mesh";
00697     sGroup        = QT_TR_NOOP("Mesh");
00698     sMenuText     = QT_TR_NOOP("Cut mesh");
00699     sToolTipText  = QT_TR_NOOP("Cuts a mesh with a picked polygon");
00700     sWhatsThis    = "Mesh_PolyCut";
00701     sStatusTip    = QT_TR_NOOP("Cuts a mesh with a picked polygon");
00702     sPixmap       = "mesh_cut";
00703 }
00704 
00705 void CmdMeshPolyCut::activated(int iMsg)
00706 {
00707     std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00708     for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
00709         if (it == docObj.begin()) {
00710             Gui::Document* doc = getActiveGuiDocument();
00711             Gui::MDIView* view = doc->getActiveView();
00712             if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00713                 Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
00714                 viewer->setEditing(true);
00715                 viewer->startSelection(Gui::View3DInventorViewer::Clip);
00716                 viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::clipMeshCallback);
00717             }
00718             else {
00719                 return;
00720             }
00721         }
00722 
00723         Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it);
00724         if (pVP->isVisible())
00725             pVP->startEditing();
00726     }
00727 }
00728 
00729 bool CmdMeshPolyCut::isActive(void)
00730 {
00731     // Check for the selected mesh feature (all Mesh types)
00732     if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
00733         return false;
00734 
00735     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00736     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00737         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00738         return !viewer->isEditing();
00739     }
00740 
00741     return false;
00742 }
00743 
00744 //--------------------------------------------------------------------------------------
00745 
00746 DEF_STD_CMD_A(CmdMeshPolySplit);
00747 
00748 CmdMeshPolySplit::CmdMeshPolySplit()
00749   : Command("Mesh_PolySplit")
00750 {
00751     sAppModule    = "Mesh";
00752     sGroup        = QT_TR_NOOP("Mesh");
00753     sMenuText     = QT_TR_NOOP("Split mesh");
00754     sToolTipText  = QT_TR_NOOP("Splits a mesh into two meshes");
00755     sWhatsThis    = "Mesh_PolySplit";
00756     sStatusTip    = QT_TR_NOOP("Splits a mesh into two meshes");
00757 }
00758 
00759 void CmdMeshPolySplit::activated(int iMsg)
00760 {
00761     std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00762     for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
00763         if (it == docObj.begin()) {
00764             Gui::Document* doc = getActiveGuiDocument();
00765             Gui::MDIView* view = doc->getActiveView();
00766             if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00767                 Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
00768                 viewer->setEditing(true);
00769                 viewer->startSelection(Gui::View3DInventorViewer::Clip);
00770                 viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::partMeshCallback);
00771             }
00772             else {
00773                 return;
00774             }
00775         }
00776 
00777         Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it);
00778         pVP->startEditing();
00779     }
00780 }
00781 
00782 bool CmdMeshPolySplit::isActive(void)
00783 {
00784     // Check for the selected mesh feature (all Mesh types)
00785     if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
00786         return false;
00787 
00788     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00789     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00790         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00791         return !viewer->isEditing();
00792     }
00793 
00794     return false;
00795 }
00796 
00797 //--------------------------------------------------------------------------------------
00798 
00799 DEF_STD_CMD_A(CmdMeshToolMesh);
00800 
00801 CmdMeshToolMesh::CmdMeshToolMesh()
00802   :Command("Mesh_ToolMesh")
00803 {
00804   sAppModule    = "Mesh";
00805   sGroup        = QT_TR_NOOP("Mesh");
00806   sMenuText     = QT_TR_NOOP("Segment by tool mesh");
00807   sToolTipText  = QT_TR_NOOP("Creates a segment from a given tool mesh");
00808   sWhatsThis    = "Mesh_ToolMesh";
00809   sStatusTip    = QT_TR_NOOP("Creates a segment from a given tool mesh");
00810 }
00811 
00812 void CmdMeshToolMesh::activated(int iMsg)
00813 {
00814   std::vector<App::DocumentObject*> fea = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00815   if ( fea.size() == 2 )
00816   {
00817     std::string fName = getUniqueObjectName("MeshSegment");
00818     App::DocumentObject* mesh = fea.front();
00819     App::DocumentObject* tool = fea.back();
00820 
00821     openCommand("Segment by tool mesh");
00822     doCommand(Doc, "import Mesh");
00823     doCommand(Gui, "import MeshGui");
00824     doCommand(Doc,
00825       "App.activeDocument().addObject(\"Mesh::SegmentByMesh\",\"%s\")\n"
00826       "App.activeDocument().%s.Source = App.activeDocument().%s\n"
00827       "App.activeDocument().%s.Tool = App.activeDocument().%s\n",
00828       fName.c_str(), fName.c_str(),  mesh->getNameInDocument(), fName.c_str(), tool->getNameInDocument() );
00829 
00830     commitCommand();
00831     updateActive();
00832 
00833     App::Document* pDoc = getDocument();
00834     App::DocumentObject * pObj = pDoc->getObject( fName.c_str() );
00835 
00836     if ( pObj )
00837     {
00838       doCommand(Gui,"Gui.hide(\"%s\")", mesh->getNameInDocument());
00839       doCommand(Gui,"Gui.hide(\"%s\")", tool->getNameInDocument());
00840       getSelection().clearSelection();
00841     }
00842   }
00843 }
00844 
00845 bool CmdMeshToolMesh::isActive(void)
00846 {
00847   // Check for the selected mesh feature (all Mesh types)
00848   return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2;
00849 }
00850 
00851 //--------------------------------------------------------------------------------------
00852 
00853 DEF_STD_CMD_A(CmdMeshEvaluation);
00854 
00855 CmdMeshEvaluation::CmdMeshEvaluation()
00856   :Command("Mesh_Evaluation")
00857 {
00858     sAppModule    = "Mesh";
00859     sGroup        = QT_TR_NOOP("Mesh");
00860     // needs two ampersands to display one
00861     sMenuText     = QT_TR_NOOP("Evaluate && Repair mesh...");
00862     sToolTipText  = QT_TR_NOOP("Opens a dialog to analyze and repair a mesh");
00863     sWhatsThis    = "Mesh_Evaluation";
00864     sStatusTip    = QT_TR_NOOP("Opens a dialog to analyze and repair a mesh");
00865 }
00866 
00867 void CmdMeshEvaluation::activated(int iMsg)
00868 {
00869     if (MeshGui::DockEvaluateMeshImp::hasInstance()) {
00870         MeshGui::DockEvaluateMeshImp::instance()->show();
00871         return;
00872     }
00873 
00874     MeshGui::DlgEvaluateMeshImp* dlg = MeshGui::DockEvaluateMeshImp::instance();
00875     dlg->setAttribute(Qt::WA_DeleteOnClose);
00876     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
00877     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
00878         dlg->setMesh((Mesh::Feature*)(*it));
00879         break;
00880     }
00881 
00882     dlg->show();
00883 }
00884 
00885 bool CmdMeshEvaluation::isActive(void)
00886 {
00887     App::Document* doc = App::GetApplication().getActiveDocument();
00888     if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
00889         return false;
00890     return true;
00891 }
00892 
00893 //--------------------------------------------------------------------------------------
00894 
00895 DEF_STD_CMD_A(CmdMeshEvaluateFacet);
00896 
00897 CmdMeshEvaluateFacet::CmdMeshEvaluateFacet()
00898   :Command("Mesh_EvaluateFacet")
00899 {
00900     sAppModule    = "Mesh";
00901     sGroup        = QT_TR_NOOP("Mesh");
00902     sMenuText     = QT_TR_NOOP("Face info");
00903     sToolTipText  = QT_TR_NOOP("Information about face");
00904     sWhatsThis    = "Mesh_EvaluateFacet";
00905     sStatusTip    = QT_TR_NOOP("Information about face");
00906     sPixmap       = "mesh_pipette";
00907 }
00908 
00909 void CmdMeshEvaluateFacet::activated(int iMsg)
00910 {
00911     Gui::Document* doc = Gui::Application::Instance->activeDocument();
00912     Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
00913     if (view) {
00914         Gui::View3DInventorViewer* viewer = view->getViewer();
00915         viewer->setEditing(true);
00916         viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_pipette"),4,29));
00917         viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::faceInfoCallback);
00918      }
00919 }
00920 
00921 bool CmdMeshEvaluateFacet::isActive(void)
00922 {
00923     App::Document* doc = App::GetApplication().getActiveDocument();
00924     if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
00925         return false;
00926 
00927     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00928     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00929         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00930         return !viewer->isEditing();
00931     }
00932 
00933     return false;
00934 }
00935 
00936 //--------------------------------------------------------------------------------------
00937 
00938 DEF_STD_CMD_A(CmdMeshRemoveComponents);
00939 
00940 CmdMeshRemoveComponents::CmdMeshRemoveComponents()
00941   : Command("Mesh_RemoveComponents")
00942 {
00943     sAppModule    = "Mesh";
00944     sGroup        = QT_TR_NOOP("Mesh");
00945     sMenuText     = QT_TR_NOOP("Remove components...");
00946     sToolTipText  = QT_TR_NOOP("Remove topologic independent components from the mesh");
00947     sWhatsThis    = "Mesh_RemoveComponents";
00948     sStatusTip    = QT_TR_NOOP("Remove topologic independent components from the mesh");
00949 }
00950 
00951 void CmdMeshRemoveComponents::activated(int iMsg)
00952 {
00953     Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
00954     if (!dlg) {
00955         dlg = new MeshGui::TaskRemoveComponents();
00956         dlg->setButtonPosition(Gui::TaskView::TaskDialog::South);
00957     }
00958     Gui::Control().showDialog(dlg);
00959 }
00960 
00961 bool CmdMeshRemoveComponents::isActive(void)
00962 {
00963     // Check for the selected mesh feature (all Mesh types)
00964     App::Document* doc = getDocument();
00965     return (doc && doc->countObjectsOfType
00966             (Mesh::Feature::getClassTypeId()) > 0
00967             && !Gui::Control().activeDialog());
00968 }
00969 
00970 //--------------------------------------------------------------------------------------
00971 
00972 DEF_STD_CMD_A(CmdMeshRemoveCompByHand);
00973 
00974 CmdMeshRemoveCompByHand::CmdMeshRemoveCompByHand()
00975   :Command("Mesh_RemoveCompByHand")
00976 {
00977     sAppModule    = "Mesh";
00978     sGroup        = QT_TR_NOOP("Mesh");
00979     sMenuText     = QT_TR_NOOP("Remove components by hand...");
00980     sToolTipText  = QT_TR_NOOP("Mark a component to remove it from the mesh");
00981     sWhatsThis    = "Mesh_RemoveCompByHand";
00982     sStatusTip    = QT_TR_NOOP("Mark a component to remove it from the mesh");
00983 }
00984 
00985 void CmdMeshRemoveCompByHand::activated(int iMsg)
00986 {
00987     Gui::Document* doc = Gui::Application::Instance->activeDocument();
00988     Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
00989     if (view) {
00990         Gui::View3DInventorViewer* viewer = view->getViewer();
00991         viewer->setEditing(true);
00992         //viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_pipette"),4,29));
00993         viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::markPartCallback);
00994     }
00995 }
00996 
00997 bool CmdMeshRemoveCompByHand::isActive(void)
00998 {
00999     App::Document* doc = App::GetApplication().getActiveDocument();
01000     if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
01001         return false;
01002 
01003     Gui::View3DInventor* view = dynamic_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow());
01004     if (view) {
01005         Gui::View3DInventorViewer* viewer = view->getViewer();
01006         return !viewer->isEditing();
01007     }
01008 
01009     return false;
01010 }
01011 
01012 //--------------------------------------------------------------------------------------
01013 
01014 DEF_STD_CMD_A(CmdMeshEvaluateSolid);
01015 
01016 CmdMeshEvaluateSolid::CmdMeshEvaluateSolid()
01017   :Command("Mesh_EvaluateSolid")
01018 {
01019     sAppModule    = "Mesh";
01020     sGroup        = QT_TR_NOOP("Mesh");
01021     sMenuText     = QT_TR_NOOP("Check solid mesh");
01022     sToolTipText  = QT_TR_NOOP("Checks whether the mesh is a solid");
01023     sWhatsThis    = "Mesh_EvaluateSolid";
01024     sStatusTip    = QT_TR_NOOP("Checks whether the mesh is a solid");
01025 }
01026 
01027 void CmdMeshEvaluateSolid::activated(int iMsg)
01028 {
01029     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
01030     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
01031         Mesh::Feature* mesh = (Mesh::Feature*)(*it);
01032         QString msg;
01033         if (mesh->Mesh.getValue().getKernel().HasOpenEdges())
01034             msg = QObject::tr("The mesh '%1' is not a solid.")
01035                 .arg(QString::fromAscii(mesh->Label.getValue()));
01036         else
01037             msg = QObject::tr("The mesh '%1' is a solid.")
01038                 .arg(QString::fromAscii(mesh->Label.getValue()));
01039         QMessageBox::information(Gui::getMainWindow(), QObject::tr("Solid Mesh"), msg);
01040     }
01041 }
01042 
01043 bool CmdMeshEvaluateSolid::isActive(void)
01044 {
01045     // Check for the selected mesh feature (all Mesh types)
01046     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1;
01047 }
01048 
01049 //--------------------------------------------------------------------------------------
01050 
01051 DEF_STD_CMD_A(CmdMeshSmoothing);
01052 
01053 CmdMeshSmoothing::CmdMeshSmoothing()
01054   :Command("Mesh_Smoothing")
01055 {
01056     sAppModule    = "Mesh";
01057     sGroup        = QT_TR_NOOP("Mesh");
01058     sMenuText     = QT_TR_NOOP("Smooth...");
01059     sToolTipText  = QT_TR_NOOP("Smooth the selected meshes");
01060     sWhatsThis    = "Mesh_Smoothing";
01061     sStatusTip    = QT_TR_NOOP("Smooth the selected meshes");
01062 }
01063 
01064 void CmdMeshSmoothing::activated(int iMsg)
01065 {
01066     MeshGui::DlgSmoothing dlg(Gui::getMainWindow());
01067     if (dlg.exec() == QDialog::Accepted) {
01068         Gui::WaitCursor wc;
01069         openCommand("Mesh Smoothing");
01070         std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
01071         for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
01072             Mesh::Feature* mesh = (Mesh::Feature*)*it;
01073             Mesh::MeshObject* mm = mesh->Mesh.startEditing();
01074             switch (dlg.method()) {
01075                 case MeshGui::DlgSmoothing::Taubin:
01076                     {
01077                         MeshCore::TaubinSmoothing s(mm->getKernel());
01078                         s.SetLambda(dlg.lambdaStep());
01079                         s.SetMicro(dlg.microStep());
01080                         s.Smooth(dlg.iterations());
01081                     }   break;
01082                 case MeshGui::DlgSmoothing::Laplace:
01083                     {
01084                         MeshCore::LaplaceSmoothing s(mm->getKernel());
01085                         s.SetLambda(dlg.lambdaStep());
01086                         s.Smooth(dlg.iterations());
01087                     }   break;
01088                 default:
01089                     break;
01090             }
01091             mesh->Mesh.finishEditing();
01092         }
01093         commitCommand();
01094     }
01095 }
01096 
01097 bool CmdMeshSmoothing::isActive(void)
01098 {
01099     // Check for the selected mesh feature (all Mesh types)
01100     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0;
01101 }
01102 
01103 //--------------------------------------------------------------------------------------
01104 
01105 DEF_STD_CMD_A(CmdMeshHarmonizeNormals);
01106 
01107 CmdMeshHarmonizeNormals::CmdMeshHarmonizeNormals()
01108   :Command("Mesh_HarmonizeNormals")
01109 {
01110     sAppModule    = "Mesh";
01111     sGroup        = QT_TR_NOOP("Mesh");
01112     sMenuText     = QT_TR_NOOP("Harmonize normals");
01113     sToolTipText  = QT_TR_NOOP("Harmonizes the normals of the mesh");
01114     sWhatsThis    = "Mesh_HarmonizeNormals";
01115     sStatusTip    = QT_TR_NOOP("Harmonizes the normals of the mesh");
01116 }
01117 
01118 void CmdMeshHarmonizeNormals::activated(int iMsg)
01119 {
01120     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
01121     openCommand("Harmonize mesh normals");
01122     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
01123         doCommand(Doc,"App.activeDocument().getObject(\"%s\").Mesh.harmonizeNormals()"
01124                      ,(*it)->getNameInDocument());
01125     }
01126     commitCommand();
01127     updateActive();
01128 }
01129 
01130 bool CmdMeshHarmonizeNormals::isActive(void)
01131 {
01132     // Check for the selected mesh feature (all Mesh types)
01133     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0;
01134 }
01135 
01136 //--------------------------------------------------------------------------------------
01137 
01138 DEF_STD_CMD_A(CmdMeshFlipNormals);
01139 
01140 CmdMeshFlipNormals::CmdMeshFlipNormals()
01141   :Command("Mesh_FlipNormals")
01142 {
01143     sAppModule    = "Mesh";
01144     sGroup        = QT_TR_NOOP("Mesh");
01145     sMenuText     = QT_TR_NOOP("Flip normals");
01146     sToolTipText  = QT_TR_NOOP("Flips the normals of the mesh");
01147     sWhatsThis    = "Mesh_FlipNormals";
01148     sStatusTip    = QT_TR_NOOP("Flips the normals of the mesh");
01149 }
01150 
01151 void CmdMeshFlipNormals::activated(int iMsg)
01152 {
01153     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
01154     openCommand("Flip mesh normals");
01155     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
01156         doCommand(Doc,"App.activeDocument().getObject(\"%s\").Mesh.flipNormals()"
01157                      ,(*it)->getNameInDocument());
01158     }
01159     commitCommand();
01160     updateActive();
01161 }
01162 
01163 bool CmdMeshFlipNormals::isActive(void)
01164 {
01165     // Check for the selected mesh feature (all Mesh types)
01166     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0;
01167 }
01168 
01169 //--------------------------------------------------------------------------------------
01170 
01171 DEF_STD_CMD_A(CmdMeshBoundingBox);
01172 
01173 CmdMeshBoundingBox::CmdMeshBoundingBox()
01174   :Command("Mesh_BoundingBox")
01175 {
01176     sAppModule    = "Mesh";
01177     sGroup        = QT_TR_NOOP("Mesh");
01178     sMenuText     = QT_TR_NOOP("Boundings info...");
01179     sToolTipText  = QT_TR_NOOP("Shows the boundings of the selected mesh");
01180     sWhatsThis    = "Mesh_BoundingBox";
01181     sStatusTip    = QT_TR_NOOP("Shows the boundings of the selected mesh");
01182 }
01183 
01184 void CmdMeshBoundingBox::activated(int iMsg)
01185 {
01186     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
01187     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
01188         const MeshCore::MeshKernel& rMesh = ((Mesh::Feature*)(*it))->Mesh.getValue().getKernel();
01189         const Base::BoundBox3f& box = rMesh.GetBoundBox();
01190 
01191         Base::Console().Message("Boundings: Min=<%f,%f,%f>, Max=<%f,%f,%f>\n",
01192                                 box.MinX,box.MinY,box.MinZ,box.MaxX,box.MaxY,box.MaxZ);
01193 
01194         QString bound = QObject::tr("Min=<%1,%2,%3>\n\nMax=<%4,%5,%6>")
01195             .arg(box.MinX).arg(box.MinY).arg(box.MinZ)
01196             .arg(box.MaxX).arg(box.MaxY).arg(box.MaxZ);
01197         QMessageBox::information(Gui::getMainWindow(), QObject::tr("Boundings"), bound);
01198         break;
01199     }
01200 }
01201 
01202 bool CmdMeshBoundingBox::isActive(void)
01203 {
01204     // Check for the selected mesh feature (all Mesh types)
01205     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1;
01206 }
01207 
01208 //--------------------------------------------------------------------------------------
01209 
01210 DEF_STD_CMD_A(CmdMeshBuildRegularSolid);
01211 
01212 CmdMeshBuildRegularSolid::CmdMeshBuildRegularSolid()
01213   :Command("Mesh_BuildRegularSolid")
01214 {
01215     sAppModule    = "Mesh";
01216     sGroup        = QT_TR_NOOP("Mesh");
01217     sMenuText     = QT_TR_NOOP("Regular solid...");
01218     sToolTipText  = QT_TR_NOOP("Builds a regular solid");
01219     sWhatsThis    = "Mesh_BuildRegularSolid";
01220     sStatusTip    = QT_TR_NOOP("Builds a regular solid");
01221     sPixmap       = "solid_mesh";
01222 }
01223 
01224 void CmdMeshBuildRegularSolid::activated(int iMsg)
01225 {
01226     MeshGui::SingleDlgRegularSolidImp::instance()->show();
01227 }
01228 
01229 bool CmdMeshBuildRegularSolid::isActive(void)
01230 {
01231     // Check for the selected mesh feature (all Mesh types)
01232     return (!MeshGui::SingleDlgRegularSolidImp::hasInstance())&&hasActiveDocument();
01233 }
01234 
01235 //--------------------------------------------------------------------------------------
01236 
01237 DEF_STD_CMD_A(CmdMeshFillupHoles);
01238 
01239 CmdMeshFillupHoles::CmdMeshFillupHoles()
01240   :Command("Mesh_FillupHoles")
01241 {
01242     sAppModule    = "Mesh";
01243     sGroup        = QT_TR_NOOP("Mesh");
01244     sMenuText     = QT_TR_NOOP("Fill holes...");
01245     sToolTipText  = QT_TR_NOOP("Fill holes of the mesh");
01246     sWhatsThis    = "Mesh_FillupHoles";
01247     sStatusTip    = QT_TR_NOOP("Fill holes of the mesh");
01248 }
01249 
01250 void CmdMeshFillupHoles::activated(int iMsg)
01251 {
01252     std::vector<App::DocumentObject*> meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId());
01253     bool ok;
01254     int FillupHolesOfLength = QInputDialog::getInteger(Gui::getMainWindow(), QObject::tr("Fill holes"),
01255                                 QObject::tr("Fill holes with maximum number of edges:"), 3, 3, 10000, 1, &ok);
01256     if (!ok) return;
01257     openCommand("Fill up holes");
01258     for (std::vector<App::DocumentObject*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
01259         doCommand(Doc,"App.activeDocument().getObject(\"%s\").Mesh.fillupHoles(%d)"
01260                      ,(*it)->getNameInDocument(), FillupHolesOfLength);
01261     }
01262     commitCommand();
01263     updateActive();
01264 }
01265 
01266 bool CmdMeshFillupHoles::isActive(void)
01267 {
01268     // Check for the selected mesh feature (all Mesh types)
01269     return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0;
01270 }
01271 
01272 //--------------------------------------------------------------------------------------
01273 
01274 DEF_STD_CMD_A(CmdMeshFillInteractiveHole);
01275 
01276 CmdMeshFillInteractiveHole::CmdMeshFillInteractiveHole()
01277   :Command("Mesh_FillInteractiveHole")
01278 {
01279     sAppModule    = "Mesh";
01280     sGroup        = QT_TR_NOOP("Mesh");
01281     sMenuText     = QT_TR_NOOP("Close hole");
01282     sToolTipText  = QT_TR_NOOP("Close holes interactively");
01283     sWhatsThis    = "Mesh_FillInteractiveHole";
01284     sStatusTip    = QT_TR_NOOP("Close holes interactively");
01285     sPixmap       = "mesh_boundary";
01286 }
01287 
01288 void CmdMeshFillInteractiveHole::activated(int iMsg)
01289 {
01290     Gui::Document* doc = Gui::Application::Instance->activeDocument();
01291     Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
01292     if (view) {
01293         Gui::View3DInventorViewer* viewer = view->getViewer();
01294         viewer->setEditing(true);
01295         viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_fillhole"),5,5));
01296         viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::fillHoleCallback);
01297      }
01298 }
01299 
01300 bool CmdMeshFillInteractiveHole::isActive(void)
01301 {
01302     App::Document* doc = App::GetApplication().getActiveDocument();
01303     if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0)
01304         return false;
01305 
01306     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
01307     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
01308         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
01309         return !viewer->isEditing();
01310     }
01311 
01312     return false;
01313 }
01314 
01315 void CreateMeshCommands(void)
01316 {
01317     Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
01318     rcCmdMgr.addCommand(new CmdMeshImport());
01319     rcCmdMgr.addCommand(new CmdMeshExport());
01320     rcCmdMgr.addCommand(new CmdMeshVertexCurvature());
01321     rcCmdMgr.addCommand(new CmdMeshVertexCurvatureInfo());
01322     rcCmdMgr.addCommand(new CmdMeshUnion());
01323     rcCmdMgr.addCommand(new CmdMeshDifference());
01324     rcCmdMgr.addCommand(new CmdMeshIntersection());
01325     rcCmdMgr.addCommand(new CmdMeshDemolding());
01326     rcCmdMgr.addCommand(new CmdMeshPolySegm());
01327     rcCmdMgr.addCommand(new CmdMeshPolySelect());
01328     rcCmdMgr.addCommand(new CmdMeshAddFacet());
01329     rcCmdMgr.addCommand(new CmdMeshPolyCut());
01330     rcCmdMgr.addCommand(new CmdMeshPolySplit());
01331     rcCmdMgr.addCommand(new CmdMeshToolMesh());
01332     rcCmdMgr.addCommand(new CmdMeshTransform());
01333     rcCmdMgr.addCommand(new CmdMeshEvaluation());
01334     rcCmdMgr.addCommand(new CmdMeshEvaluateFacet());
01335     rcCmdMgr.addCommand(new CmdMeshEvaluateSolid());
01336     rcCmdMgr.addCommand(new CmdMeshHarmonizeNormals());
01337     rcCmdMgr.addCommand(new CmdMeshFlipNormals());
01338     rcCmdMgr.addCommand(new CmdMeshSmoothing());
01339     rcCmdMgr.addCommand(new CmdMeshBoundingBox());
01340     rcCmdMgr.addCommand(new CmdMeshBuildRegularSolid());
01341     rcCmdMgr.addCommand(new CmdMeshFillupHoles());
01342     rcCmdMgr.addCommand(new CmdMeshRemoveComponents());
01343     rcCmdMgr.addCommand(new CmdMeshFillInteractiveHole());
01344     rcCmdMgr.addCommand(new CmdMeshRemoveCompByHand());
01345     rcCmdMgr.addCommand(new CmdMeshFromGeometry());
01346 }

Generated on Wed Nov 23 19:00:01 2011 for FreeCAD by  doxygen 1.6.1