Mod/Fem/Gui/Command.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de)              *
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 # include <QMessageBox>
00027 #endif
00028 
00029 #include <App/Application.h>
00030 #include <App/Document.h>
00031 #include <App/DocumentObject.h>
00032 #include <Gui/Application.h>
00033 #include <Gui/Command.h>
00034 #include <Gui/MainWindow.h>
00035 #include <Gui/FileDialog.h>
00036 #include <Gui/Selection.h>
00037 #include <Gui/Document.h>
00038 
00039 #include <Mod/Fem/App/FemMeshObject.h>
00040 
00041 
00042 using namespace std;
00043 
00044 DEF_STD_CMD_A(CmdFemCreateFromShape);
00045 
00046 CmdFemCreateFromShape::CmdFemCreateFromShape()
00047   : Command("Fem_CreateFromShape")
00048 {
00049     sAppModule      = "Fem";
00050     sGroup          = QT_TR_NOOP("Fem");
00051     sMenuText       = QT_TR_NOOP("Create FEM mesh");
00052     sToolTipText    = QT_TR_NOOP("Create FEM mesh from shape");
00053     sWhatsThis      = sToolTipText;
00054     sStatusTip      = sToolTipText;
00055     sPixmap         = "Fem_FemMesh";
00056 }
00057 
00058 void CmdFemCreateFromShape::activated(int iMsg)
00059 {
00060     Base::Type type = Base::Type::fromName("Part::Feature");
00061     std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType(type);
00062 
00063     openCommand("Create FEM");
00064     doCommand(Doc, "import Fem");
00065     for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
00066         App::Document* doc = (*it)->getDocument();
00067         QString name = QString::fromAscii((*it)->getNameInDocument());
00068         QString cmd = QString::fromAscii(
00069             "__fem__=Fem.FemMesh()\n"
00070             "__fem__.setShape(FreeCAD.getDocument(\"%1\").%2.Shape)\n"
00071             "h1=Fem.StdMeshers_MaxLength(0,__fem__)\n"
00072             "h1.setLength(1.0)\n"
00073             "h2=Fem.StdMeshers_LocalLength(1,__fem__)\n"
00074             "h2.setLength(1.0)\n"
00075             "h3=Fem.StdMeshers_QuadranglePreference(2,__fem__)\n"
00076             "h4=Fem.StdMeshers_Quadrangle_2D(3,__fem__)\n"
00077             "h5=Fem.StdMeshers_MaxElementArea(4,__fem__)\n"
00078             "h5.setMaxArea(1.0)\n"
00079             "h6=Fem.StdMeshers_Regular_1D(5,__fem__)\n"
00080             "__fem__.addHypothesis(h1)\n"
00081             "__fem__.addHypothesis(h2)\n"
00082             "__fem__.addHypothesis(h3)\n"
00083             "__fem__.addHypothesis(h4)\n"
00084             "__fem__.addHypothesis(h5)\n"
00085             "__fem__.addHypothesis(h6)\n"
00086             "__fem__.compute()\n"
00087             "FreeCAD.getDocument(\"%1\").addObject"
00088             "(\"Fem::FemMeshObject\",\"%2\").FemMesh=__fem__\n"
00089             "del __fem__,h1,h2,h3,h4,h5,h6\n"
00090         )
00091         .arg(QString::fromAscii(doc->getName()))
00092         .arg(name);
00093         doCommand(Doc, "%s", (const char*)cmd.toAscii());
00094     }
00095     commitCommand();
00096 }
00097 
00098 bool CmdFemCreateFromShape::isActive(void)
00099 {
00100     Base::Type type = Base::Type::fromName("Part::Feature");
00101     return Gui::Selection().countObjectsOfType(type) > 0;
00102 }
00103 
00104 
00105 void CreateFemCommands(void)
00106 {
00107     Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00108     rcCmdMgr.addCommand(new CmdFemCreateFromShape());
00109 }

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