/*************************************************************************** * Copyright (c) 2008 Werner Mayer * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ # include # include #endif #include #include #include #include #include #include #include #include #include "Workbench.h" using namespace AssemblyGui; void switchToDocument(const App::Document* doc) { if(doc->countObjects() == 0){ // -> set up a empty document std::string PartName = doc->getUniqueObjectName("Part"); std::string ProductName = doc->getUniqueObjectName("Product"); std::string RefName = doc->getUniqueObjectName((PartName + "-1").c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Tip = App.activeDocument().addObject('Assembly::Product','%s')",ProductName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ProductRef','%s')",RefName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s",ProductName.c_str(),RefName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Part','%s')",PartName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Item = App.activeDocument().%s",RefName.c_str(),PartName.c_str()); PartDesignGui::Workbench::setUpPart(dynamic_cast( doc->getObject(PartName.c_str())) ); } } /// @namespace AssemblyGui @class Workbench TYPESYSTEM_SOURCE(AssemblyGui::Workbench, Gui::StdWorkbench) Workbench::Workbench() { } Workbench::~Workbench() { } Gui::ToolBarItem* Workbench::setupToolBars() const { Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); Gui::ToolBarItem* part = new Gui::ToolBarItem(root); part->setCommand(QT_TR_NOOP("Assembly")); //*part << "Assembly_Constraint"; //*part << "Assembly_ConstraintFix"; //*part << "Assembly_ConstraintDistance"; //*part << "Assembly_ConstraintOrientation"; //*part << "Assembly_ConstraintAngle"; //*part << "Assembly_ConstraintCoincidence"; //*part << "Assembly_ConstraintAlignment"; *part << "Separator"; *part << "Assembly_AddNewPart"; *part << "Assembly_AddNewComponent"; *part << "Assembly_AddExistingComponent"; return root; } Gui::MenuItem* Workbench::setupMenuBar() const { Gui::MenuItem* root = StdWorkbench::setupMenuBar(); Gui::MenuItem* item = root->findItem("&Windows"); Gui::MenuItem* asmCmd = new Gui::MenuItem(); root->insertItem(item, asmCmd); asmCmd->setCommand("&Assembly"); *asmCmd //<< "Assembly_ConstraintFix" // << "Assembly_ConstraintDistance" // << "Assembly_ConstraintOrientation" // << "Assembly_ConstraintAngle" // << "Assembly_ConstraintCoincidence" // << "Assembly_ConstraintAlignment" << "Separator" << "Assembly_AddNewPart" << "Assembly_AddNewComponent" << "Assembly_AddExistingComponent"; Gui::MenuItem* impCmd = new Gui::MenuItem(); root->insertItem(asmCmd, impCmd); impCmd->setCommand("&Import"); *impCmd << "Assembly_Import"; return root; } Gui::ToolBarItem* Workbench::setupCommandBars() const { // Part tools Gui::ToolBarItem* root = new Gui::ToolBarItem; return root; } void Workbench::activated() { Gui::Workbench::activated(); std::vector Watcher; const char* Asm[] = { "Assembly_AddNewPart", "PartDesign_Fillet", "PartDesign_Chamfer", 0}; Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( "SELECT Assembly::Item COUNT 1", Asm, "Assembly tools", "Part_Box" )); addTaskWatcher(Watcher); Gui::Control().showTaskView(); //App::Document *doc = App::GetApplication().getActiveDocument(); //if(!doc){ // // create a new document // std::string uniqueName = App::GetApplication().getUniqueDocumentName("Assembly1"); // Gui::Command::doCommand(Gui::Command::Doc,"App.newDocument('%s')",uniqueName.c_str()); // doc = App::GetApplication().getActiveDocument(); // switchToDocument(doc); //} // show a warning about the Alpha state of FreeCAD Assembly Gui::Dialog::DlgCheckableMessageBox::showMessage( QString::fromLatin1("Assembly warning"), QString::fromLatin1( "

The Assembly module of FreeCAD is in Alpha state!

" "Use for testing purpose only! The object structure is still changing.
" "You might not be able to load your work in a newer Version of FreeCAD.

" "For further information see the Assembly project page:
" " http://www.freecadweb.org/wiki/index.php?title=Assembly_project
" "Or the Assembly dedicated portion of our forum:
" " http://forum.freecadweb.org/
" ), false, QString::fromLatin1("Don't tell me again, I know the risk!") ); // now we should have a document! //assert(doc); //if(doc->countObjects()==0){ // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','Assembly')"); // Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().Assembly)"); //} // Let us be notified when a document is activated, so that we can update the ActivePartObject Gui::Application::Instance->signalActiveDocument.connect(boost::bind(&Workbench::slotActiveDocument, this, _1)); App::GetApplication().signalNewDocument.connect(boost::bind(&Workbench::slotNewDocument, this, _1)); App::GetApplication().signalFinishRestoreDocument.connect(boost::bind(&Workbench::slotFinishRestoreDocument, this, _1)); App::GetApplication().signalDeleteDocument.connect(boost::bind(&Workbench::slotDeleteDocument, this, _1)); Gui::Control().showModelView(); } void Workbench::deactivated() { Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(None)"); // Disconnect all document signals... Gui::Application::Instance->signalActiveDocument.disconnect(boost::bind(&Workbench::slotActiveDocument, this, _1)); App::GetApplication().signalNewDocument.disconnect(boost::bind(&Workbench::slotNewDocument, this, _1)); App::GetApplication().signalFinishRestoreDocument.disconnect(boost::bind(&Workbench::slotFinishRestoreDocument, this, _1)); App::GetApplication().signalDeleteDocument.disconnect(boost::bind(&Workbench::slotDeleteDocument, this, _1)); Gui::Workbench::deactivated(); removeTaskWatcher(); } void Workbench::slotActiveDocument(const Gui::Document& Doc) { switchToDocument(Doc.getDocument()); } void Workbench::slotNewDocument(const App::Document& Doc) { switchToDocument(&Doc); } void Workbench::slotFinishRestoreDocument(const App::Document& Doc) { switchToDocument(&Doc); } void Workbench::slotDeleteDocument(const App::Document&) { //ActivePartObject = 0; //ActiveGuiDoc = 0; //ActiveAppDoc = 0; //ActiveVp = 0; }