Assembly: Document handling and some fixes

This commit is contained in:
jriegel 2014-09-22 12:24:35 +02:00 committed by Stefan Tröger
parent 0feabcc8ff
commit 0013374818
6 changed files with 108 additions and 26 deletions

View File

@ -25,6 +25,7 @@ set(AssemblyGui_LIBS
#${ODE_LIBRARIES}
Assembly
PartGui
PartDesignGui
FreeCADGui
)

View File

@ -28,13 +28,15 @@
// Importing of App classes
#ifdef FC_OS_WIN32
# define AssemblyExport __declspec(dllimport)
# define PartGuiExport __declspec(dllimport)
# define PartExport __declspec(dllimport)
# define AssemblyGuiExport __declspec(dllexport)
# define AssemblyExport __declspec(dllimport)
# define PartGuiExport __declspec(dllimport)
# define PartDesignGuiExport __declspec(dllimport)
# define PartExport __declspec(dllimport)
# define AssemblyGuiExport __declspec(dllexport)
#else // for Linux
# define AssemblyExport
# define PartGuiExport
# define PartDesignGuiExport
# define PartExport
# define AssemblyGuiExport
#endif

View File

@ -24,7 +24,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoGroup.h>
#include <math.h>
#include <Inventor/nodes/SoGroup.h>
#include <QMessageBox>
#endif
@ -35,7 +36,7 @@
#include <Gui/Application.h>
#include <Mod/Assembly/App/Product.h>
#include <Mod/Assembly/App/PartRef.h>
#include <Mod/Assembly/App/ProductRef.h>
using namespace AssemblyGui;
@ -93,12 +94,16 @@ std::vector<std::string> ViewProviderProductRef::getDisplayModes(void) const
std::vector<App::DocumentObject*> ViewProviderProductRef::claimChildren(void)const
{
return (static_cast<Assembly::Product*>(getObject())->Items.getValues());
std::vector<App::DocumentObject*> ret(1);
ret[0] = static_cast<Assembly::ProductRef*>(getObject())->Item.getValue();
return ret;
}
std::vector<App::DocumentObject*> ViewProviderProductRef::claimChildren3D(void)const
{
return static_cast<Assembly::Product*>(getObject())->Items.getValues();
std::vector<App::DocumentObject*> ret(1);
ret[0] = static_cast<Assembly::ProductRef*>(getObject())->Item.getValue();
return ret;
}
void ViewProviderProductRef::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)

View File

@ -25,19 +25,47 @@
#ifndef _PreComp_
# include <qobject.h>
# include <boost/bind.hpp>
#endif
#include "Workbench.h"
#include <App/Application.h>
#include <Gui/MenuManager.h>
#include <Gui/ToolBarManager.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/Document.h>
#include <Gui/DlgCheckableMessageBox.h>
#include <Mod/PartDesign/Gui/Workbench.h>
#include <App/Part.h>
#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<App::Part *>( doc->getObject(PartName.c_str())) );
}
}
/// @namespace AssemblyGui @class Workbench
TYPESYSTEM_SOURCE(AssemblyGui::Workbench, Gui::StdWorkbench)
@ -127,14 +155,18 @@ void Workbench::activated()
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();
//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"),
@ -152,12 +184,19 @@ void Workbench::activated()
);
// now we should have a document!
assert(doc);
//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));
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)");
}
Gui::Control().showModelView();
}
@ -166,8 +205,36 @@ 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;
}

View File

@ -21,10 +21,11 @@
***************************************************************************/
#ifndef IMAGE_WORKBENCH_H
#define IMAGE_WORKBENCH_H
#ifndef ASSEMBLY_WORKBENCH_H
#define ASSEMBLY_WORKBENCH_H
#include <Gui/Workbench.h>
#include <Gui/Application.h>
namespace AssemblyGui {
@ -49,9 +50,14 @@ protected:
Gui::ToolBarItem* setupCommandBars() const;
Gui::MenuItem* setupMenuBar() const;
private:
void slotActiveDocument(const Gui::Document&);
void slotFinishRestoreDocument(const App::Document&);
void slotNewDocument(const App::Document&);
void slotDeleteDocument(const App::Document&);
};
} // namespace AssemblyGui
#endif // IMAGE_WORKBENCH_H
#endif // ASSEMBLY_WORKBENCH_H

View File

@ -113,6 +113,7 @@ void CmdPartDesignBody::activated(int iMsg)
// if not, creating a part and set it up by calling the appropiated function in Workbench
PartName = getUniqueObjectName("Part");
doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str());
doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr(PartName.c_str()).toStdString().c_str());
PartDesignGui::Workbench::setUpPart(dynamic_cast<App::Part *>(getDocument()->getObject(PartName.c_str())));
}else
PartName = actPart->getNameInDocument();