void PropertyFileIncluded::Save (Base::Writer &writer) const { if (writer.isForceXML()) { if (!_cValue.empty()) { Base::FileInfo file(_cValue.c_str()); writer.Stream() << writer.ind() << "<FileIncluded data=\"" << file.fileName() << "\">" << std::endl; // write the file in the XML stream writer.incInd(); writer.insertBinFile(_cValue.c_str()); writer.decInd(); writer.Stream() << writer.ind() <<"</FileIncluded>" << endl; } else writer.Stream() << writer.ind() << "<FileIncluded data=\"\"/>" << std::endl; } else { // instead initiate an extra file if (!_cValue.empty()) { Base::FileInfo file(_cValue.c_str()); writer.Stream() << writer.ind() << "<FileIncluded file=\"" << writer.addFile(file.fileName().c_str(), this) << "\"/>" << std::endl; } else writer.Stream() << writer.ind() << "<FileIncluded file=\"\"/>" << std::endl; } }
void DynamicProperty::Save (Base::Writer &writer) const { std::map<std::string,Property*> Map; getPropertyMap(Map); writer.incInd(); // indentation for 'Properties Count' writer.Stream() << writer.ind() << "<Properties Count=\"" << Map.size() << "\">" << std::endl; std::map<std::string,Property*>::iterator it; for (it = Map.begin(); it != Map.end(); ++it) { writer.incInd(); // indentation for 'Property name' // check whether a static or dynamic property std::map<std::string,PropData>::const_iterator pt = props.find(it->first); if (pt == props.end()) { writer.Stream() << writer.ind() << "<Property name=\"" << it->first << "\" type=\"" << it->second->getTypeId().getName() << "\">" << std::endl; } else { writer.Stream() << writer.ind() << "<Property name=\"" << it->first << "\" type=\"" << it->second->getTypeId().getName() << "\" group=\"" << encodeAttribute(pt->second.group) << "\" doc=\"" << encodeAttribute(pt->second.doc) << "\" attr=\"" << pt->second.attr << "\" ro=\"" << pt->second.readonly << "\" hide=\"" << pt->second.hidden << "\">" << std::endl; } writer.incInd(); // indentation for the actual property try { // We must make sure to handle all exceptions accordingly so that // the project file doesn't get invalidated. In the error case this // means to proceed instead of aborting the write operation. // Don't write transient properties if (!(getPropertyType(it->second) & Prop_Transient)) it->second->Save(writer); } catch (const Base::Exception &e) { Base::Console().Error("%s\n", e.what()); } catch (const std::exception &e) { Base::Console().Error("%s\n", e.what()); } catch (const char* e) { Base::Console().Error("%s\n", e); } #ifndef FC_DEBUG catch (...) { Base::Console().Error("DynamicProperty::Save: Unknown C++ exception thrown. Try to continue...\n"); } #endif writer.decInd(); // indentation for the actual property writer.Stream() << writer.ind() << "</Property>" << std::endl; writer.decInd(); // indentation for 'Property name' } writer.Stream() << writer.ind() << "</Properties>" << std::endl; writer.decInd(); // indentation for 'Properties Count' }
void PropertyIntegerList::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<IntegerList count=\"" << getSize() <<"\">" << endl; writer.incInd(); for(int i = 0;i<getSize(); i++) writer.Stream() << writer.ind() << "<I v=\"" << _lValueList[i] <<"\"/>" << endl; ; writer.decInd(); writer.Stream() << writer.ind() << "</IntegerList>" << endl ; }
void PropertyLinkList::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<LinkList count=\"" << getSize() <<"\">" << endl; writer.incInd(); for(int i = 0;i<getSize(); i++) writer.Stream() << writer.ind() << "<Link value=\"" << _lValueList[i]->getNameInDocument() <<"\"/>" << endl; ; writer.decInd(); writer.Stream() << writer.ind() << "</LinkList>" << endl ; }
/** * Saves the properties of the view providers. */ void Document::SaveDocFile (Base::Writer &writer) const { writer.Stream() << "<?xml version='1.0' encoding='utf-8'?>" << std::endl << "<!--" << std::endl << " FreeCAD Document, see http://free-cad.sourceforge.net for more information..." << std::endl << "-->" << std::endl; writer.Stream() << "<Document SchemaVersion=\"1\">" << std::endl; std::map<const App::DocumentObject*,ViewProviderDocumentObject*>::const_iterator it; // writing the view provider names itself writer.incInd(); // indention for 'ViewProviderData Count' writer.Stream() << writer.ind() << "<ViewProviderData Count=\"" << d->_ViewProviderMap.size() <<"\">" << std::endl; bool xml = writer.isForceXML(); //writer.setForceXML(true); writer.incInd(); // indention for 'ViewProvider name' for(it = d->_ViewProviderMap.begin(); it != d->_ViewProviderMap.end(); ++it) { const App::DocumentObject* doc = it->first; ViewProvider* obj = it->second; writer.Stream() << writer.ind() << "<ViewProvider name=\"" << doc->getNameInDocument() << "\" " << "expanded=\"" << (doc->testStatus(App::Expand) ? 1:0) << "\">" << std::endl; obj->Save(writer); writer.Stream() << writer.ind() << "</ViewProvider>" << std::endl; } writer.setForceXML(xml); writer.decInd(); // indention for 'ViewProvider name' writer.Stream() << writer.ind() << "</ViewProviderData>" << std::endl; writer.decInd(); // indention for 'ViewProviderData Count' // set camera settings QString viewPos; if (d->_pcAppWnd->sendHasMsgToActiveView("GetCamera")) { const char* ppReturn=0; d->_pcAppWnd->sendMsgToActiveView("GetCamera",&ppReturn); // remove the first line because it's a comment like '#Inventor V2.1 ascii' QStringList lines = QString(QString::fromAscii(ppReturn)).split(QLatin1String("\n")); if (lines.size() > 1) { lines.pop_front(); viewPos = lines.join(QLatin1String(" ")); } } writer.incInd(); // indention for camera settings writer.Stream() << writer.ind() << "<Camera settings=\"" << (const char*)viewPos.toAscii() <<"\"/>" << std::endl; writer.decInd(); // indention for camera settings writer.Stream() << "</Document>" << std::endl; }
void PropertyStringList::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<StringList count=\"" << getSize() <<"\">" << endl; writer.incInd(); for(int i = 0;i<getSize(); i++) { std::string val = encodeAttribute(_lValueList[i]); writer.Stream() << writer.ind() << "<String value=\"" << val <<"\"/>" << endl; } writer.decInd(); writer.Stream() << writer.ind() << "</StringList>" << endl ; }
void PropertyMeshKernel::Save (Base::Writer &writer) const { if (writer.isForceXML()) { writer.Stream() << writer.ind() << "<Mesh>" << std::endl; MeshCore::MeshOutput saver(_meshObject->getKernel()); saver.SaveXML(writer); } else { writer.Stream() << writer.ind() << "<Mesh file=\"" << writer.addFile("MeshKernel.bms", this) << "\"/>" << std::endl; } }
void PropertyColumnWidths::Save(Base::Writer &writer) const { // Save column information writer.Stream() << writer.ind() << "<ColumnInfo Count=\"" << size() << "\">" << std::endl; writer.incInd(); // indention for 'ColumnInfo' std::map<int, int>::const_iterator coli = begin(); while (coli != end()) { writer.Stream() << writer.ind() << "<Column name=\"" << columnName(coli->first) << "\" width=\"" << coli->second << "\" />" << std::endl; ++coli; } writer.decInd(); // indention for 'ColumnInfo' writer.Stream() << writer.ind() << "</ColumnInfo>" << std::endl; }
void PropertyExpressionEngine::Save(Base::Writer &writer) const { writer.Stream() << writer.ind() << "<ExpressionEngine count=\"" << expressions.size() <<"\">" << std::endl; writer.incInd(); for (ExpressionMap::const_iterator it = expressions.begin(); it != expressions.end(); ++it) { writer.Stream() << writer.ind() << "<Expression path=\"" << Property::encodeAttribute(it->first.toString()) <<"\"" << " expression=\"" << Property::encodeAttribute(it->second.expression->toString()) << "\""; if (it->second.comment.size() > 0) writer.Stream() << " comment=\"" << Property::encodeAttribute(it->second.comment) << "\""; writer.Stream() << "/>" << std::endl; } writer.decInd(); writer.Stream() << writer.ind() << "</ExpressionEngine>" << std::endl; }
void PropertyLinkSub::Save (Base::Writer &writer) const { const char* internal_name = ""; // it can happen that the object is still alive but is not part of the document anymore and thus // returns 0 if (_pcLinkSub && _pcLinkSub->getNameInDocument()) internal_name = _pcLinkSub->getNameInDocument(); writer.Stream() << writer.ind() << "<LinkSub value=\"" << internal_name <<"\" count=\"" << _cSubList.size() <<"\">" << std::endl; writer.incInd(); for(unsigned int i = 0;i<_cSubList.size(); i++) writer.Stream() << writer.ind() << "<Sub value=\"" << _cSubList[i]<<"\"/>" << endl; writer.decInd(); writer.Stream() << writer.ind() << "</LinkSub>" << endl ; }
void PropertyContainer::Save (Base::Writer &writer) const { std::map<std::string,Property*> Map; getPropertyMap(Map); // ignore the properties we won't store size_t ct = std::count_if(Map.begin(), Map.end(), std::bind2nd(PropertyAttribute <std::pair<std::string,Property*> >(this), Prop_Transient)); size_t size = Map.size() - ct; writer.incInd(); // indentation for 'Properties Count' writer.Stream() << writer.ind() << "<Properties Count=\"" << size << "\">" << endl; std::map<std::string,Property*>::iterator it; for (it = Map.begin(); it != Map.end(); ++it) { // Don't write transient properties if (!(getPropertyType(it->second) & Prop_Transient)) { writer.incInd(); // indentation for 'Property name' writer.Stream() << writer.ind() << "<Property name=\"" << it->first << "\" type=\"" << it->second->getTypeId().getName() << "\">" << endl;; writer.incInd(); // indentation for the actual property try { // We must make sure to handle all exceptions accordingly so that // the project file doesn't get invalidated. In the error case this // means to proceed instead of aborting the write operation. it->second->Save(writer); } catch (const Base::Exception &e) { Base::Console().Error("%s\n", e.what()); } catch (const std::exception &e) { Base::Console().Error("%s\n", e.what()); } catch (const char* e) { Base::Console().Error("%s\n", e); } #ifndef FC_DEBUG catch (...) { Base::Console().Error("PropertyContainer::Save: Unknown C++ exception thrown. Try to continue...\n"); } #endif writer.decInd(); // indentation for the actual property writer.Stream() << writer.ind() << "</Property>" << endl; writer.decInd(); // indentation for 'Property name' } } writer.Stream() << writer.ind() << "</Properties>" << endl; writer.decInd(); // indentation for 'Properties Count' }
void PropertyRowHeights::Save(Base::Writer &writer) const { // Save row information writer.Stream() << writer.ind() << "<RowInfo Count=\"" << size() << "\">" << std::endl; writer.incInd(); // indention for 'RowInfo' std::map<int, int>::const_iterator ri = begin(); while (ri != end()) { writer.Stream() << writer.ind() << "<Row name=\"" << rowName(ri->first) << "\" height=\"" << ri->second << "\" />" << std::endl; ++ri; } writer.decInd(); // indention for 'RowInfo' writer.Stream() << writer.ind() << "</RowInfo>" << std::endl; }
void PropertyLinkList::Save(Base::Writer &writer) const { writer.Stream() << writer.ind() << "<LinkList count=\"" << getSize() << "\">" << endl; writer.incInd(); for (int i = 0; i<getSize(); i++) { DocumentObject* obj = _lValueList[i]; if (obj) writer.Stream() << writer.ind() << "<Link value=\"" << obj->getNameInDocument() << "\"/>" << endl; else writer.Stream() << writer.ind() << "<Link value=\"\"/>" << endl; } writer.decInd(); writer.Stream() << writer.ind() << "</LinkList>" << endl; }
void PropertyGreyValueList::Save (Base::Writer &writer) const { if (writer.isForceXML()) { writer.Stream() << writer.ind() << "<FloatList count=\"" << getSize() <<"\">" << endl; writer.incInd(); for(int i = 0;i<getSize(); i++) writer.Stream() << writer.ind() << "<F v=\"" << _lValueList[i] <<"\"/>" << endl; ; writer.decInd(); writer.Stream() << writer.ind() <<"</FloatList>" << endl ; } else { writer.Stream() << writer.ind() << "<FloatList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl; } }
void PropertyPartShape::Save (Base::Writer &writer) const { if(!writer.isForceXML()) { //See SaveDocFile(), RestoreDocFile() if (writer.getMode("BinaryBrep")) { writer.Stream() << writer.ind() << "<Part file=\"" << writer.addFile("PartShape.bin", this) << "\"/>" << std::endl; } else { writer.Stream() << writer.ind() << "<Part file=\"" << writer.addFile("PartShape.brp", this) << "\"/>" << std::endl; } } }
void PropertyCurvatureList::Save (Base::Writer &writer) const { if (!writer.isForceXML()) { writer.Stream() << writer.ind() << "<CurvatureList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl; } }
void PointKernel::Save (Base::Writer &writer) const { if (!writer.isForceXML()) { writer.Stream() << writer.ind() << "<Points file=\"" << writer.addFile(writer.ObjectName.c_str(), this) << "\" " << "mtrx=\"" << _Mtrx.toString() << "\"/>" << std::endl; } }
void PropertyBool::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<Bool value=\"" ; if (_lValue) writer.Stream() << "true" <<"\"/>" ; else writer.Stream() << "false" <<"\"/>" ; writer.Stream() << std::endl; }
void PropertyEnumeration::Save(Base::Writer &writer) const { writer.Stream() << writer.ind() << "<Integer value=\"" << _lValue <<"\""; if (_CustomEnum) writer.Stream() << " CustomEnum=\"true\""; writer.Stream() << "/>" << std::endl; if (_CustomEnum) { std::vector<std::string> items = getEnumVector(); writer.Stream() << writer.ind() << "<CustomEnumList count=\"" << items.size() <<"\">" << endl; writer.incInd(); for(std::vector<std::string>::iterator it = items.begin(); it != items.end(); ++it) { std::string val = encodeAttribute(*it); writer.Stream() << writer.ind() << "<Enum value=\"" << val <<"\"/>" << endl; } writer.decInd(); writer.Stream() << writer.ind() << "</CustomEnumList>" << endl; } }
void PropertyMaterial::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<PropertyMaterial ambientColor=\"" << _cMat.ambientColor.getPackedValue() << "\" diffuseColor=\"" << _cMat.diffuseColor.getPackedValue() << "\" specularColor=\"" << _cMat.specularColor.getPackedValue() << "\" emissiveColor=\"" << _cMat.emissiveColor.getPackedValue() << "\" shininess=\"" << _cMat.shininess << "\" transparency=\"" << _cMat.transparency << "\"/>" << endl; }
void Document::exportObjects(const std::vector<App::DocumentObject*>& obj, Base::Writer& writer) { writer.Stream() << "<?xml version='1.0' encoding='utf-8'?>" << std::endl; writer.Stream() << "<Document SchemaVersion=\"1\">" << std::endl; std::map<const App::DocumentObject*,ViewProvider*> views; for (std::vector<App::DocumentObject*>::const_iterator it = obj.begin(); it != obj.end(); ++it) { Document* doc = Application::Instance->getDocument((*it)->getDocument()); if (doc) { ViewProvider* vp = doc->getViewProvider(*it); if (vp) views[*it] = vp; } } // writing the view provider names itself writer.incInd(); // indention for 'ViewProviderData Count' writer.Stream() << writer.ind() << "<ViewProviderData Count=\"" << views.size() <<"\">" << std::endl; bool xml = writer.isForceXML(); //writer.setForceXML(true); writer.incInd(); // indention for 'ViewProvider name' std::map<const App::DocumentObject*,ViewProvider*>::const_iterator jt; for (jt = views.begin(); jt != views.end(); ++jt) { const App::DocumentObject* doc = jt->first; ViewProvider* obj = jt->second; writer.Stream() << writer.ind() << "<ViewProvider name=\"" << doc->getNameInDocument() << "\" type=\"" << obj->getTypeId().getName() << "\">" << std::endl; obj->Save(writer); writer.Stream() << writer.ind() << "</ViewProvider>" << std::endl; } writer.setForceXML(xml); writer.decInd(); // indention for 'ViewProvider name' writer.Stream() << writer.ind() << "</ViewProviderData>" << std::endl; writer.decInd(); // indention for 'ViewProviderData Count' writer.incInd(); // indention for camera settings writer.Stream() << writer.ind() << "<Camera settings=\"\"/>" << std::endl; writer.decInd(); // indention for camera settings writer.Stream() << "</Document>" << std::endl; }
void PropertyFileIncluded::Save (Base::Writer &writer) const { // when saving a document under a new file name the transient directory // name changes and thus the stored file name doesn't work any more. if (!_cValue.empty() && !Base::FileInfo(_cValue).exists()) { Base::FileInfo fi(getDocTransientPath() + "/" + _BaseFileName); if (fi.exists()) _cValue = fi.filePath(); } if (writer.isForceXML()) { if (!_cValue.empty()) { Base::FileInfo file(_cValue.c_str()); writer.Stream() << writer.ind() << "<FileIncluded data=\"" << file.fileName() << "\">" << std::endl; // write the file in the XML stream writer.incInd(); writer.insertBinFile(_cValue.c_str()); writer.decInd(); writer.Stream() << writer.ind() <<"</FileIncluded>" << endl; } else { writer.Stream() << writer.ind() << "<FileIncluded data=\"\"/>" << std::endl; } } else { // instead initiate an extra file if (!_cValue.empty()) { Base::FileInfo file(_cValue.c_str()); writer.Stream() << writer.ind() << "<FileIncluded file=\"" << writer.addFile(file.fileName().c_str(), this) << "\"/>" << std::endl; } else { writer.Stream() << writer.ind() << "<FileIncluded file=\"\"/>" << std::endl; } } }
void Cell::save(Base::Writer &writer) const { if (!isUsed()) return; writer.Stream() << writer.ind() << "<Cell "; writer.Stream() << "address=\"" << address.toString() << "\" "; if (isUsed(EXPRESSION_SET)) { std::string content; getStringContent(content); writer.Stream() << "content=\"" << App::Property::encodeAttribute(content) << "\" "; } if (isUsed(ALIGNMENT_SET)) writer.Stream() << "alignment=\"" << encodeAlignment(alignment) << "\" "; if (isUsed(STYLE_SET)) writer.Stream() << "style=\"" << encodeStyle(style) << "\" "; if (isUsed(FOREGROUND_COLOR_SET)) writer.Stream() << "foregroundColor=\"" << encodeColor(foregroundColor) << "\" "; if (isUsed(BACKGROUND_COLOR_SET)) writer.Stream() << "backgroundColor=\"" << encodeColor(backgroundColor) << "\" "; if (isUsed(DISPLAY_UNIT_SET)) writer.Stream() << "displayUnit=\"" << App::Property::encodeAttribute(displayUnit.stringRep) << "\" "; if (isUsed(ALIAS_SET)) writer.Stream() << "alias=\"" << App::Property::encodeAttribute(alias) << "\" "; if (isUsed(SPANS_SET)) { writer.Stream() << "rowSpan=\"" << rowSpan<< "\" "; writer.Stream() << "colSpan=\"" << colSpan << "\" "; } writer.Stream() << "/>" << std::endl; }
void PropertyPythonObject::Save (Base::Writer &writer) const { //if (writer.isForceXML()) { std::string repr = this->toString(); repr = Base::base64_encode((const unsigned char*)repr.c_str(), repr.size()); std::string val = /*encodeValue*/(repr); writer.Stream() << writer.ind() << "<Python value=\"" << val << "\" encoded=\"yes\""; Base::PyGILStateLocker lock; try { if (this->object.hasAttr("__module__") && this->object.hasAttr("__class__")) { Py::String mod(this->object.getAttr("__module__")); Py::Object cls(this->object.getAttr("__class__")); if (cls.hasAttr("__name__")) { Py::String name(cls.getAttr("__name__")); writer.Stream() << " module=\"" << (std::string)mod << "\"" << " class=\"" << (std::string)name << "\""; } } else { writer.Stream() << " json=\"yes\""; } } catch (Py::Exception&) { Base::PyException e; // extract the Python error text e.ReportException(); } saveObject(writer); writer.Stream() << "/>" << std::endl; //} //else { // writer.Stream() << writer.ind() << "<Python file=\"" << // writer.addFile("pickle", this) << "\"/>" << std::endl; //} }
void PropertyFloat::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<Float value=\"" << _dValue <<"\"/>" << std::endl; }
void PropertyFilletEdges::Save (Base::Writer &writer) const { if (!writer.isForceXML()) { writer.Stream() << writer.ind() << "<FilletEdges file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl; } }
void PropertyPath::Save (Base::Writer &writer) const { std::string val = encodeAttribute(_cValue.string()); writer.Stream() << writer.ind() << "<Path value=\"" << val <<"\"/>" << std::endl; }
void PropertyVector::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<PropertyVector valueX=\"" << _cVec.x << "\" valueY=\"" << _cVec.y << "\" valueZ=\"" << _cVec.z <<"\"/>" << endl; }
void PropertyLink::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<Link value=\"" << (_pcLink?_pcLink->getNameInDocument():"") <<"\"/>" << std::endl; }
void PropertyColor::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "<PropertyColor value=\"" << _cCol.getPackedValue() <<"\"/>" << endl; }