Merge branch 'master' of ssh://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad

This commit is contained in:
Jose Luis Cercos Pita 2012-11-22 18:40:56 +01:00
commit cb1f57ff8f
9 changed files with 142 additions and 151 deletions

View File

@ -579,34 +579,7 @@ void Document::Save (Base::Writer &writer) const
PropertyContainer::Save(writer);
// writing the features types
writer.incInd(); // indention for 'Objects count'
writer.Stream() << writer.ind() << "<Objects Count=\"" << d->objectArray.size() <<"\">" << endl;
writer.incInd(); // indention for 'Object type'
std::vector<DocumentObject*>::const_iterator it;
for (it = d->objectArray.begin(); it != d->objectArray.end(); ++it) {
writer.Stream() << writer.ind() << "<Object "
<< "type=\"" << (*it)->getTypeId().getName() << "\" "
<< "name=\"" << (*it)->getNameInDocument() << "\" "
<< "/>" << endl;
}
writer.decInd(); // indention for 'Object type'
writer.Stream() << writer.ind() << "</Objects>" << endl;
// writing the features itself
writer.Stream() << writer.ind() << "<ObjectData Count=\"" << d->objectArray.size() <<"\">" << endl;
writer.incInd(); // indention for 'Object name'
for (it = d->objectArray.begin(); it != d->objectArray.end(); ++it) {
writer.Stream() << writer.ind() << "<Object name=\"" << (*it)->getNameInDocument() << "\">" << endl;
(*it)->Save(writer);
writer.Stream() << writer.ind() << "</Object>" << endl;
}
writer.decInd(); // indention for 'Object name'
writer.Stream() << writer.ind() << "</ObjectData>" << endl;
writer.decInd(); // indention for 'Objects count'
writeObjects(d->objectArray, writer);
writer.Stream() << "</Document>" << endl;
}
@ -685,37 +658,7 @@ void Document::Restore(Base::XMLReader &reader)
} // SchemeVersion "3" or higher
else if ( scheme >= 3 ) {
// read the feature types
reader.readElement("Objects");
Cnt = reader.getAttributeAsInteger("Count");
for (i=0 ;i<Cnt ;i++) {
reader.readElement("Object");
string type = reader.getAttribute("type");
string name = reader.getAttribute("name");
try {
addObject(type.c_str(),name.c_str());
}
catch ( Base::Exception& ) {
Base::Console().Message("Cannot create object '%s'\n", name.c_str());
}
}
reader.readEndElement("Objects");
// read the features itself
reader.readElement("ObjectData");
Cnt = reader.getAttributeAsInteger("Count");
for (i=0 ;i<Cnt ;i++) {
reader.readElement("Object");
string name = reader.getAttribute("name");
DocumentObject* pObj = getObject(name.c_str());
if (pObj) { // check if this feature has been registered
pObj->StatusBits.set(4);
pObj->Restore(reader);
pObj->StatusBits.reset(4);
}
reader.readEndElement("Object");
}
reader.readEndElement("ObjectData");
readObjects(reader);
}
reader.readEndElement("Document");
@ -732,6 +675,20 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& obj,
writer.Stream() << "<Properties Count=\"0\">" << endl;
writer.Stream() << "</Properties>" << endl;
// writing the object types
writeObjects(obj, writer);
writer.Stream() << "</Document>" << endl;
// Hook for others to add further data.
signalExportObjects(obj, writer);
// write additional files
writer.writeFiles();
}
void Document::writeObjects(const std::vector<App::DocumentObject*>& obj,
Base::Writer &writer) const
{
// writing the features types
writer.incInd(); // indention for 'Objects count'
writer.Stream() << writer.ind() << "<Objects Count=\"" << obj.size() <<"\">" << endl;
@ -741,7 +698,7 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& obj,
for (it = obj.begin(); it != obj.end(); ++it) {
writer.Stream() << writer.ind() << "<Object "
<< "type=\"" << (*it)->getTypeId().getName() << "\" "
<< "name=\"" << (*it)->getNameInDocument() << "\" "
<< "name=\"" << (*it)->getNameInDocument() << "\" "
<< "/>" << endl;
}
@ -761,42 +718,31 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& obj,
writer.decInd(); // indention for 'Object name'
writer.Stream() << writer.ind() << "</ObjectData>" << endl;
writer.decInd(); // indention for 'Objects count'
writer.Stream() << "</Document>" << endl;
// Hook for others to add further data.
signalExportObjects(obj, writer);
// write additional files
writer.writeFiles();
}
std::vector<App::DocumentObject*>
Document::importObjects(std::istream& input)
Document::readObjects(Base::XMLReader& reader)
{
std::vector<App::DocumentObject*> objs;
zipios::ZipInputStream zipstream(input);
Base::XMLReader reader("<memory>", zipstream);
int i,Cnt;
reader.readElement("Document");
long scheme = reader.getAttributeAsInteger("SchemaVersion");
reader.DocumentSchema = scheme;
// read the object types
std::map<std::string, std::string> nameMap;
reader.readElement("Objects");
Cnt = reader.getAttributeAsInteger("Count");
for (i=0 ;i<Cnt ;i++) {
int Cnt = reader.getAttributeAsInteger("Count");
for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Object");
string type = reader.getAttribute("type");
string name = reader.getAttribute("name");
std::string type = reader.getAttribute("type");
std::string name = reader.getAttribute("name");
try {
// Use name from XML as is and do NOT remove trailing digits because
// otherwise we may cause a dependency to itself
// Example: Object 'Cut001' references object 'Cut' and removing the
// digits we make an object 'Cut' referencing itself.
App::DocumentObject* o = addObject(type.c_str(),name.c_str());
objs.push_back(o);
// use this name for the later access because an object with
// the given name may already exist
nameMap[name] = o->getNameInDocument();
reader.addName(name.c_str(), o->getNameInDocument());
}
catch (Base::Exception&) {
Base::Console().Message("Cannot create object '%s'\n", name.c_str());
@ -807,9 +753,9 @@ Document::importObjects(std::istream& input)
// read the features itself
reader.readElement("ObjectData");
Cnt = reader.getAttributeAsInteger("Count");
for (i=0 ;i<Cnt ;i++) {
for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Object");
std::string name = nameMap[reader.getAttribute("name")];
std::string name = reader.getName(reader.getAttribute("name"));
DocumentObject* pObj = getObject(name.c_str());
if (pObj) { // check if this feature has been registered
pObj->StatusBits.set(4);
@ -820,12 +766,26 @@ Document::importObjects(std::istream& input)
}
reader.readEndElement("ObjectData");
return objs;
}
std::vector<App::DocumentObject*>
Document::importObjects(Base::XMLReader& reader)
{
reader.readElement("Document");
long scheme = reader.getAttributeAsInteger("SchemaVersion");
reader.DocumentSchema = scheme;
std::vector<App::DocumentObject*> objs = readObjects(reader);
reader.readEndElement("Document");
signalImportObjects(objs, reader);
reader.readFiles(zipstream);
// reset all touched
for (std::vector<DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it)
for (std::vector<DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it) {
(*it)->onDocumentRestored();
(*it)->purgeTouched();
}
return objs;
}

View File

@ -115,7 +115,7 @@ public:
void restore (void);
void exportObjects(const std::vector<App::DocumentObject*>&, std::ostream&);
void exportGraphviz(std::ostream&);
std::vector<App::DocumentObject*> importObjects(std::istream&);
std::vector<App::DocumentObject*> importObjects(Base::XMLReader& reader);
/// Opens the document from its file name
//void open (void);
/// Is the document already saved to a file
@ -266,6 +266,8 @@ protected:
/// checks if a valid transaction is open
void _checkTransaction(void);
void breakDependency(DocumentObject* pcObject, bool clear);
std::vector<App::DocumentObject*> readObjects(Base::XMLReader& reader);
void writeObjects(const std::vector<App::DocumentObject*>&, Base::Writer &writer) const;
void onChanged(const Property* prop);
/// callback from the Document objects before property will be changed

View File

@ -360,6 +360,15 @@ bool Base::XMLReader::isRegistered(Base::Persistence *Object) const
return false;
}
void Base::XMLReader::addName(const char*, const char*)
{
}
const char* Base::XMLReader::getName(const char* name) const
{
return name;
}
// ---------------------------------------------------------------------------
// Base::XMLReader: Implementation of the SAX DocumentHandler interface
// ---------------------------------------------------------------------------

View File

@ -159,6 +159,8 @@ public:
/// get all registered file names
const std::vector<std::string>& getFilenames() const;
bool isRegistered(Base::Persistence *Object) const;
virtual void addName(const char*, const char*);
virtual const char* getName(const char*) const;
//@}
/// Schema Version of the document

View File

@ -31,6 +31,7 @@
# include <QDesktopWidget>
# include <QEvent>
# include <QMessageBox>
# include <QTimer>
# include <QToolBar>
# include <QToolButton>
#endif
@ -55,13 +56,21 @@ using namespace Gui::Dialog;
* Constructs an action called \a name with parent \a parent. It also stores a pointer
* to the command object.
*/
Action::Action (Command* pcCmd,QObject * parent)
Action::Action (Command* pcCmd, QObject * parent)
: QObject(parent), _action(new QAction( this )), _pcCmd(pcCmd)
{
_action->setObjectName(QString::fromAscii(_pcCmd->getName()));
connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
}
Action::Action (Command* pcCmd, QAction* action, QObject * parent)
: QObject(parent), _action(action), _pcCmd(pcCmd)
{
_action->setParent(this);
_action->setObjectName(QString::fromAscii(_pcCmd->getName()));
connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
}
Action::~Action()
{
delete _action;
@ -257,6 +266,14 @@ void ActionGroup::setVisible( bool b )
_group->setVisible(b);
}
QAction* ActionGroup::addAction(QAction* action)
{
int index = _group->actions().size();
action = _group->addAction(action);
action->setData(QVariant(index));
return action;
}
QAction* ActionGroup::addAction(const QString& text)
{
int index = _group->actions().size();
@ -289,6 +306,14 @@ void ActionGroup::onActivated ()
_pcCmd->invoke(this->property("defaultAction").toInt());
}
/**
* Activates the command.
*/
void ActionGroup::onActivated (int index)
{
_pcCmd->invoke(index);
}
/**
* Activates the command.
*/
@ -410,6 +435,8 @@ void WorkbenchComboBox::onActivated(int i)
int index = itemData(i).toInt();
WorkbenchActionEvent* ev = new WorkbenchActionEvent(this->actions()[index]);
QApplication::postEvent(this->group, ev);
// TODO: Test if we can use this instead
//QTimer::singleShot(20, this->actions()[i], SLOT(trigger()));
}
void WorkbenchComboBox::onActivated(QAction* action)

View File

@ -45,6 +45,8 @@ class GuiExport Action : public QObject
public:
Action (Command* pcCmd, QObject * parent = 0);
/// Action takes ownership of the 'action' object.
Action (Command* pcCmd, QAction* action, QObject * parent);
virtual ~Action();
virtual void addTo (QWidget * w);
@ -100,6 +102,7 @@ public:
void setVisible (bool);
void setDropDownMenu(bool b) { _dropDown = b; }
QAction* addAction(QAction*);
QAction* addAction(const QString&);
QList<QAction*> actions() const;
int checkedAction() const;
@ -107,6 +110,7 @@ public:
public Q_SLOTS:
void onActivated ();
void onActivated (int);
void onActivated (QAction*);
protected:

View File

@ -42,10 +42,22 @@ namespace Gui {
class XMLMergeReader : public Base::XMLReader
{
public:
XMLMergeReader(const std::map<std::string, std::string>& name, const char* FileName, std::istream& str)
XMLMergeReader(std::map<std::string, std::string>& name, const char* FileName, std::istream& str)
: Base::XMLReader(FileName, str), nameMap(name)
{}
void addName(const char* s1, const char* s2)
{
nameMap[s1] = s2;
}
const char* getName(const char* name) const
{
std::map<std::string, std::string>::const_iterator it = nameMap.find(name);
if (it != nameMap.end())
return it->second.c_str();
else
return name;
}
protected:
void startElement(const XMLCh* const uri, const XMLCh* const localname,
const XMLCh* const qname,
@ -75,7 +87,7 @@ protected:
}
private:
const std::map<std::string, std::string>& nameMap;
std::map<std::string, std::string>& nameMap;
typedef std::pair<std::string, std::string> PropertyTag;
std::stack<PropertyTag> propertyStack;
};
@ -104,64 +116,14 @@ unsigned int MergeDocuments::getMemSize (void) const
std::vector<App::DocumentObject*>
MergeDocuments::importObjects(std::istream& input)
{
//std::map<std::string, std::string> nameMap;
std::vector<App::DocumentObject*> objs;
zipios::ZipInputStream zipstream(input);
XMLMergeReader reader(nameMap,"<memory>", zipstream);
this->nameMap.clear();
this->stream = new zipios::ZipInputStream(input);
XMLMergeReader reader(this->nameMap,"<memory>", *stream);
std::vector<App::DocumentObject*> objs = appdoc->importObjects(reader);
int i,Cnt;
reader.readElement("Document");
long scheme = reader.getAttributeAsInteger("SchemaVersion");
reader.DocumentSchema = scheme;
delete this->stream;
this->stream = 0;
// read the object types
nameMap.clear();
reader.readElement("Objects");
Cnt = reader.getAttributeAsInteger("Count");
for (i=0 ;i<Cnt ;i++) {
reader.readElement("Object");
std::string type = reader.getAttribute("type");
std::string name = reader.getAttribute("name");
try {
// Use name from XML as is and do NOT remove trailing digits because
// otherwise we may cause a dependency to itself
// Example: Object 'Cut001' references object 'Cut' and removing the
// digits we make an object 'Cut' referencing itself.
App::DocumentObject* o = appdoc->addObject(type.c_str(),name.c_str());
objs.push_back(o);
// use this name for the later access because an object with
// the given name may already exist
nameMap[name] = o->getNameInDocument();
}
catch (Base::Exception&) {
Base::Console().Message("Cannot create object '%s'\n", name.c_str());
}
}
reader.readEndElement("Objects");
// read the features itself
reader.readElement("ObjectData");
Cnt = reader.getAttributeAsInteger("Count");
for (i=0 ;i<Cnt ;i++) {
reader.readElement("Object");
std::string name = nameMap[reader.getAttribute("name")];
App::DocumentObject* pObj = appdoc->getObject(name.c_str());
if (pObj) { // check if this feature has been registered
// pObj->StatusBits.set(4);
pObj->Restore(reader);
// pObj->StatusBits.reset(4);
}
reader.readEndElement("Object");
}
reader.readEndElement("ObjectData");
reader.readEndElement("Document");
appdoc->signalImportObjects(objs, reader);
reader.readFiles(zipstream);
// reset all touched
for (std::vector<App::DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it)
(*it)->purgeTouched();
return objs;
}
@ -173,6 +135,8 @@ void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Ba
if (vp) vp->hide();
}
Restore(r);
r.readFiles(*this->stream);
}
void MergeDocuments::exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w)

View File

@ -27,6 +27,9 @@
#include <boost/signals.hpp>
#include <Base/Persistence.h>
namespace zipios {
class ZipInputStream;
}
namespace App {
class Document;
class DocumentObject;
@ -49,6 +52,7 @@ public:
void RestoreDocFile(Base::Reader & r);
private:
zipios::ZipInputStream* stream;
App::Document* appdoc;
Gui::Document* document;
std::vector<App::DocumentObject*> objects;

View File

@ -25,6 +25,8 @@
#ifndef _PreComp_
# include <sstream>
# include <QApplication>
# include <QEvent>
# include <QFileInfo>
# include <QPixmap>
# include <boost/signals.hpp>
@ -68,7 +70,19 @@ using namespace Gui;
namespace Gui {
class ViewProviderPythonFeatureObserver
class PropertyEvent : public QEvent
{
public:
PropertyEvent(App::Property* p1, App::Property* p2)
: QEvent(QEvent::Type(QEvent::User)), p1(p1), p2(p2)
{
}
App::Property* p1;
App::Property* p2;
};
class ViewProviderPythonFeatureObserver : public QObject
{
public:
/// The one and only instance.
@ -80,13 +94,19 @@ public:
void slotDeleteDocument(const Gui::Document&);
private:
void customEvent(QEvent* e)
{
PropertyEvent* pe = static_cast<PropertyEvent*>(e);
pe->p1->Paste(*pe->p2);
delete pe->p2;
}
static ViewProviderPythonFeatureObserver* _singleton;
ViewProviderPythonFeatureObserver();
~ViewProviderPythonFeatureObserver();
typedef std::map<
const App::DocumentObject*,
std::string
App::Property*
> ObjectProxy;
std::map<const App::Document*, ObjectProxy> proxyMap;
@ -133,8 +153,8 @@ void ViewProviderPythonFeatureObserver::slotAppendObject(const Gui::ViewProvider
try {
App::Property* prop = vp.getPropertyByName("Proxy");
if (prop && prop->isDerivedFrom(App::PropertyPythonObject::getClassTypeId())) {
static_cast<App::PropertyPythonObject*>(prop)->fromString(jt->second);
static_cast<App::PropertyPythonObject*>(prop)->touch();
// make this delayed so that the corresponding item in the tree view is accessible
QApplication::postEvent(this, new PropertyEvent(prop, jt->second));
it->second.erase(jt);
}
}
@ -162,8 +182,7 @@ void ViewProviderPythonFeatureObserver::slotDeleteObject(const Gui::ViewProvider
try {
App::Property* prop = vp.getPropertyByName("Proxy");
if (prop && prop->isDerivedFrom(App::PropertyPythonObject::getClassTypeId())) {
std::string proxy = static_cast<App::PropertyPythonObject*>(prop)->toString();
proxyMap[doc][docobj] = proxy;
proxyMap[doc][docobj] = prop->Copy();
}
}
catch (Py::Exception& e) {