00001 /*************************************************************************** 00002 * Copyright (c) 2011 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 <Gui/Application.h> 00030 #include <Gui/Document.h> 00031 #include <Gui/Selection.h> 00032 #include <Gui/Command.h> 00033 #include <Gui/MainWindow.h> 00034 #include <Gui/DlgEditFileIncludeProptertyExternal.h> 00035 00036 #include <Mod/Part/App/Geometry.h> 00037 #include <Mod/Sketcher/App/SketchObject.h> 00038 00039 #include "ViewProviderSketch.h" 00040 00041 using namespace std; 00042 using namespace SketcherGui; 00043 using namespace Sketcher; 00044 00045 bool isAlterGeoActive(Gui::Document *doc) 00046 { 00047 if (doc) 00048 // checks if a Sketch Viewprovider is in Edit and is in no special mode 00049 if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) 00050 if (dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit()) 00051 ->getSketchMode() == ViewProviderSketch::STATUS_NONE) 00052 if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) 00053 return true; 00054 return false; 00055 } 00056 00057 namespace SketcherGui { 00058 00059 00060 /* Constrain commands =======================================================*/ 00061 DEF_STD_CMD_A(CmdSketcherToggleConstruction); 00062 00063 CmdSketcherToggleConstruction::CmdSketcherToggleConstruction() 00064 :Command("Sketcher_ToggleConstruction") 00065 { 00066 sAppModule = "Sketcher"; 00067 sGroup = QT_TR_NOOP("Sketcher"); 00068 sMenuText = QT_TR_NOOP("Toggle construction line"); 00069 sToolTipText = QT_TR_NOOP("Toggles the currently selected lines to/from construction mode"); 00070 sWhatsThis = sToolTipText; 00071 sStatusTip = sToolTipText; 00072 sPixmap = "Sketcher_AlterConstruction"; 00073 sAccel = "T"; 00074 eType = ForEdit; 00075 } 00076 00077 void CmdSketcherToggleConstruction::activated(int iMsg) 00078 { 00079 // get the selection 00080 std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); 00081 00082 // only one sketch with its subelements are allowed to be selected 00083 if (selection.size() != 1) { 00084 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), 00085 QObject::tr("Select edge(s) from the sketch.")); 00086 return; 00087 } 00088 00089 // get the needed lists and objects 00090 const std::vector<std::string> &SubNames = selection[0].getSubNames(); 00091 Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject()); 00092 const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); 00093 00094 // undo command open 00095 openCommand("toggle draft from/to draft"); 00096 00097 // go through the selected subelements 00098 for(std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it){ 00099 // only handle edges 00100 if (it->size() > 4 && it->substr(0,4) == "Edge") { 00101 int index=std::atoi(it->substr(4,4000).c_str()); 00102 // issue the actual commands to toggle 00103 doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),index); 00104 } 00105 } 00106 // finish the transaction and update 00107 commitCommand(); 00108 updateActive(); 00109 00110 // clear the selection (convenience) 00111 getSelection().clearSelection(); 00112 } 00113 00114 bool CmdSketcherToggleConstruction::isActive(void) 00115 { 00116 return isAlterGeoActive( getActiveGuiDocument() ); 00117 } 00118 00119 00120 00121 } 00122 00123 00124 void CreateSketcherCommandsAlterGeo(void) 00125 { 00126 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); 00127 00128 rcCmdMgr.addCommand(new CmdSketcherToggleConstruction()); 00129 } 00130