SmartArt: Preparations for roundtrip

The DiagramModel uses 4 mandatory and three optional XMLDoms
for it's data. These get imported, but to get to a roundtrip
we will need to be able to create & save these again.

Last changes prepared this by deleting XMLDoms which were no
longer valid dependent of changes done to that DiagramModel.
When exporting the availability of these gets checked and if
all are there, it gets exported as Diagram (in MSO format,
not yet in ODF). If nothing was changed the original Doms
get exported - untouched.

That test will now try - if e.g. the most important XMLDom
OOXData is missing - to re-create this in that action. The 1st
one which I now implemented that is the OOXData which homes
the Point/Connections/BGFill data (and some more).

Due to this needing testing I for now encapsulated this
to a EnvVar called ACTIVATE_RECREATE_DIAGRAM_DATADOMS, so
this will for now only happen when this is set. Anyways all
that stuff is still behind the 'experimental features' wall.
This is and stays experimental for now.

These are already deep changes which need to get tested and
get to master, opening the path to experiment with it and
refine it. Due to the EnvVar gate no real changes should
happen in master, but due to the changes around it this
will need to be checked this way.

Change-Id: Iabba69b19387e45f1028843a25f3bae1fc4f8fe8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197676
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
This commit is contained in:
Armin Le Grand (collabora)
2026-01-22 10:59:37 +01:00
committed by Armin Le Grand
parent 4ca7291c93
commit bd047bbb9e
30 changed files with 510 additions and 139 deletions
@@ -15372,8 +15372,8 @@ svx::ThemeDialog::initColorSets()
svx::ThemeDialog::runThemeColorEditDialog()
svx::classification::containsProperty(com::sun::star::uno::Sequence<com::sun::star::beans::Property> const&, std::basic_string_view<char16_t, std::char_traits<char16_t> >)
svx::classification::convertClassificationResultToString(std::__debug::vector<svx::ClassificationResult, std::allocator<svx::ClassificationResult> > const&)
svx::diagram::DiagramData::addConnection(svx::diagram::TypeConstant, rtl::OUString const&, rtl::OUString const&)
svx::diagram::DiagramData::getChildrenString(rtl::OUStringBuffer&, svx::diagram::Point const*, int) const
svx::diagram::DiagramData_svx::addConnection(svx::diagram::TypeConstant, rtl::OUString const&, rtl::OUString const&)
svx::diagram::DiagramData_svx::getChildrenString(rtl::OUStringBuffer&, svx::diagram::Point const*, int) const
svx::diagram::DiagramDataState::DiagramDataState(std::__debug::vector<svx::diagram::Connection, std::allocator<svx::diagram::Connection> >, std::__debug::vector<svx::diagram::Point, std::allocator<svx::diagram::Point> >)
svx::diagram::DiagramFrameHdl::CreateB2dIAObject()
svx::diagram::DiagramFrameHdl::DiagramFrameHdl(basegfx::B2DHomMatrix const&)
@@ -15746,8 +15746,8 @@ svx::administrateDatabaseRegistration(weld::Window*)
svx::checkForFontWork(SdrObject const*)
svx::classification::containsProperty(com::sun::star::uno::Sequence<com::sun::star::beans::Property> const&, std::basic_string_view<char16_t, std::char_traits<char16_t> >)
svx::classification::convertClassificationResultToString(std::vector<svx::ClassificationResult, std::allocator<svx::ClassificationResult> > const&)
svx::diagram::DiagramData::addConnection(svx::diagram::TypeConstant, rtl::OUString const&, rtl::OUString const&)
svx::diagram::DiagramData::getChildrenString(rtl::OUStringBuffer&, svx::diagram::Point const*, int) const
svx::diagram::DiagramData_svx::addConnection(svx::diagram::TypeConstant, rtl::OUString const&, rtl::OUString const&)
svx::diagram::DiagramData_svx::getChildrenString(rtl::OUStringBuffer&, svx::diagram::Point const*, int) const
svx::diagram::DiagramFrameHdl::CreateB2dIAObject()
svx::diagram::DiagramFrameHdl::DiagramFrameHdl(basegfx::B2DHomMatrix const&)
svx::diagram::IDiagramHelper::AddAdditionalVisualization(SdrObjGroup const&, SdrHdlList&)
+1 -1
View File
@@ -684,7 +684,7 @@ merge svx::IControllerFeatureInvalidation with FmXFormShell
merge svx::IFocusObserver with svx::FmTextControlShell
maybe merge svx::ODataAccessObjectTransferable with dbaui::ODataClipboard, in modules svx and dbaccess
merge svx::RegistrationItemSetHolder with svx::DatabaseRegistrationDialog
maybe merge svx::diagram::DiagramData with oox::drawingml::DiagramData, in modules svx and oox
maybe merge svx::diagram::DiagramData_svx with oox::drawingml::DiagramData, in modules svx and oox
maybe merge svx::diagram::IDiagramHelper with oox::drawingml::AdvancedDiagramHelper, in modules svx and oox
maybe merge svx::sidebar::InspectorTextPanel with sw::sidebar::WriterInspectorTextPanel, in modules svx and sw
merge svx::sidebar::SvxShapeCommandsMap with svx::sidebar::DefaultShapesPanel
@@ -731,7 +731,7 @@ include/svx/diagram/datamodel.hxx:153
include/svx/diagram/datamodel.hxx:155
svx::diagram::Point mbIsPlaceholder _Bool
include/svx/diagram/datamodel.hxx:266
svx::diagram::DiagramData maConnectionNameMap ConnectionNameMap
svx::diagram::DiagramData_svx maConnectionNameMap ConnectionNameMap
include/svx/fillctrl.hxx:83
FillControl mxColorDispatch std::unique_ptr<ToolbarUnoDispatcher>
include/svx/float3d.hxx:202
+1 -1
View File
@@ -14,7 +14,7 @@
#include <svx/svdmodel.hxx>
#include <svx/svdundo.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <svx/diagram/datamodel.hxx>
#include <svx/diagram/datamodel_svx.hxx>
#include <svx/diagram/IDiagramHelper.hxx>
DiagramDialog::DiagramDialog(weld::Window* pWindow, SdrObjGroup& rDiagram)
@@ -80,7 +80,7 @@ public:
virtual std::shared_ptr< svx::diagram::DiagramDataState > extractDiagramDataState() const override;
virtual void applyDiagramDataState(const std::shared_ptr< svx::diagram::DiagramDataState >& rState) override;
void doAnchor(SdrObjGroup& rTarget, ::oox::drawingml::Shape& rRootShape);
void doAnchor(com::sun::star::uno::Reference<com::sun::star::drawing::XShape>& rTarget, ::oox::drawingml::Shape& rRootShape);
const std::shared_ptr< ::oox::drawingml::Theme >& getOrCreateThemePtr(
const rtl::Reference< oox::shape::ShapeFilterBase>& rxFilter ) const;
@@ -89,7 +89,8 @@ public:
virtual com::sun::star::uno::Any getOOXDomValue(svx::diagram::DomMapFlag aDomMapFlag) const override;
// check if mandatory DiagramDomS exist (or can be created)
virtual bool checkOrCreateMinimalDataDoms() override;
bool checkMinimalDataDoms() const;
void tryToCreateMissingDataDoms(oox::core::XmlFilterBase& rFB);
};
}
+1 -1
View File
@@ -518,7 +518,7 @@ public:
OString WriteWdpPicture( const OUString& rFileId, const css::uno::Sequence< sal_Int8 >& rPictureData );
// Diagram helpers
OOX_DLLPUBLIC static bool PrepareToWriteAsDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape);
OOX_DLLPUBLIC bool PrepareToWriteAsDiagram(const css::uno::Reference<css::drawing::XShape>& rXRootShape);
OOX_DLLPUBLIC void WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape,
sal_Int32 nDiagramId, sal_Int32 nShapeId = -1);
void writeDiagramRels(const css::uno::Sequence<css::uno::Sequence<css::uno::Any>>& xRelSeq,
+2 -5
View File
@@ -86,7 +86,7 @@ private:
protected:
// remember associated SdrObjGroup
SdrObjGroup* mpAssociatedSdrObjGroup;
com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxGroupShape;
public:
IDiagramHelper(bool bSelfCreated);
@@ -122,16 +122,13 @@ public:
void setSelfCreated() { mbSelfCreated = true; }
// connect/disconnect to/from Group
void connectToSdrObjGroup(SdrObjGroup& rTarget);
void connectToSdrObjGroup(com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rTarget);
void disconnectFromSdrObjGroup();
static void AddAdditionalVisualization(const SdrObjGroup& rTarget, SdrHdlList& rHdlList);
// access to PropertyValues
virtual com::sun::star::uno::Any getOOXDomValue(svx::diagram::DomMapFlag aDomMapFlag) const = 0;
// check if mandatory DiagramDomS exist (or can be created)
virtual bool checkOrCreateMinimalDataDoms() = 0;
};
}} // end of namespace
@@ -34,6 +34,7 @@
#include <com/sun/star/xml/dom/XDocument.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <oox/token/tokens.hxx>
#include <sax/fshelper.hxx>
class Outliner;
@@ -71,6 +72,7 @@ struct SVXCORE_DLLPUBLIC Connection
sal_Int32 mnSourceOrder;
sal_Int32 mnDestOrder;
void writeDiagramData(sax_fastparser::FSHelperPtr& rTarget);
};
typedef std::vector< Connection > Connections;
@@ -128,13 +130,13 @@ struct SVXCORE_DLLPUBLIC Point
OUString msPresentationLayoutStyleLabel;
OUString msQuickStyleCategoryId;
OUString msQuickStyleTypeId;
OUString msResizeHandles;
TypeConstant mnXMLType;
sal_Int32 mnMaxChildren;
sal_Int32 mnPreferredChildren;
sal_Int32 mnDirection;
std::optional<sal_Int32> moHierarchyBranch;
sal_Int32 mnResizeHandles;
sal_Int32 mnCustomAngle;
sal_Int32 mnPercentageNeighbourWidth;
sal_Int32 mnPercentageNeighbourHeight;
@@ -156,6 +158,8 @@ struct SVXCORE_DLLPUBLIC Point
bool mbCustomVerticalFlip;
bool mbCustomText;
bool mbIsPlaceholder;
void writeDiagramData(sax_fastparser::FSHelperPtr& rTarget);
};
typedef std::vector< Point > Points;
@@ -178,7 +182,7 @@ typedef std::shared_ptr< DiagramDataState > DiagramDataStatePtr;
/** The collected Diagram ModelData
*/
class SVXCORE_DLLPUBLIC DiagramData
class SVXCORE_DLLPUBLIC DiagramData_svx
{
public:
typedef std::map< OUString, Point* > PointNameMap;
@@ -196,11 +200,11 @@ public:
protected:
// Make constructor protected to signal that this anyway pure virtual class
// shall not be incarnated - target to use is oox::drawingml::DiagramData
DiagramData();
// shall not be incarnated - target to use is oox::drawingml::DiagramData_oox
DiagramData_svx();
public:
virtual ~DiagramData();
virtual ~DiagramData_svx();
// creates temporary processing data from model data
virtual void buildDiagramDataModel(bool bClearOoxShapes);
@@ -243,7 +247,7 @@ protected:
::std::vector<OUString> maExtDrawings;
// The model definition, the parts available in svx.
// See evtl. parts in oox::drawingml::DiagramData that may need t obe accessed
// See evtl. parts in oox::drawingml::DiagramData_oox that may need t obe accessed
// - logic connections/associations
Connections maConnections;
@@ -272,7 +276,7 @@ protected:
OUString msBackgroundShapeModelID;
};
typedef std::shared_ptr< DiagramData > DiagramDataPtr;
typedef std::shared_ptr< DiagramData_svx > DiagramDataPtr_svx;
}
+1 -1
View File
@@ -42,7 +42,7 @@ excludelist:
- com/sun/star/drawing/LineStyle.hpp
oox/source/drawingml/shape.cxx:
# Actually used
- diagram/datamodel.hxx
- diagram/datamodel_oox.hxx
# Needed for direct member access
- com/sun/star/xml/dom/XDocument.hpp
oox/source/drawingml/textparagraph.cxx:
+1 -1
View File
@@ -156,7 +156,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
oox/source/drawingml/customshapepresetdata \
oox/source/drawingml/customshapeproperties \
oox/source/drawingml/diagram/constraintlistcontext \
oox/source/drawingml/diagram/datamodel \
oox/source/drawingml/diagram/datamodel_oox \
oox/source/drawingml/diagram/datamodelcontext \
oox/source/drawingml/diagram/diagram \
oox/source/drawingml/diagram/diagramhelper \
@@ -17,7 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "datamodel.hxx"
#include "datamodel_oox.hxx"
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -29,7 +29,11 @@
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/drawing/XShapes.hpp>
#include <editeng/unoprnms.hxx>
#include <svx/svdobj.hxx>
#include <oox/token/namespaces.hxx>
#include <oox/export/drawingml.hxx>
#include <unordered_set>
@@ -37,11 +41,11 @@ using namespace ::com::sun::star;
namespace oox::drawingml {
Shape* DiagramData::getOrCreateAssociatedShape(const svx::diagram::Point& rPoint, bool bCreateOnDemand) const
Shape* DiagramData_oox::getOrCreateAssociatedShape(const svx::diagram::Point& rPoint, bool bCreateOnDemand) const
{
if(maPointShapeMap.end() == maPointShapeMap.find(rPoint.msModelId))
{
const_cast<DiagramData*>(this)->maPointShapeMap[rPoint.msModelId] = ShapePtr();
const_cast<DiagramData_oox*>(this)->maPointShapeMap[rPoint.msModelId] = ShapePtr();
}
const ShapePtr& rShapePtr = maPointShapeMap.find(rPoint.msModelId)->second;
@@ -58,7 +62,7 @@ Shape* DiagramData::getOrCreateAssociatedShape(const svx::diagram::Point& rPoint
return rShapePtr.get();
}
void DiagramData::restoreDataFromModelToShapeAfterReCreation(const svx::diagram::Point& rPoint, Shape& rNewShape)
void DiagramData_oox::restoreDataFromModelToShapeAfterReCreation(const svx::diagram::Point& rPoint, Shape& rNewShape)
{
// If we did create a new oox::drawingml::Shape, directly apply
// available data from the Diagram ModelData to it as preparation
@@ -86,6 +90,93 @@ void DiagramData::restoreDataFromModelToShapeAfterReCreation(const svx::diagram:
}
}
void DiagramData_oox::writeDiagramData(oox::core::XmlFilterBase& rFB, sax_fastparser::FSHelperPtr& rTarget, const css::uno::Reference<css::drawing::XShape>& rXShape)
{
if (!rTarget)
return;
// write header infos
const OUString aNsDmlDiagram(rFB.getNamespaceURL(OOX_NS(dmlDiagram)));
const OUString aNsDml(rFB.getNamespaceURL(NMSP_dmlDiagram));
rTarget->startElementNS(XML_dgm, XML_dataModel,
FSNS(XML_xmlns, XML_dgm), aNsDmlDiagram,
FSNS(XML_xmlns, XML_a), aNsDml);
// write PointList
rTarget->startElementNS(XML_dgm, XML_ptLst);
for (auto& rPoint : getPoints())
rPoint.writeDiagramData(rTarget);
rTarget->endElementNS(XML_dgm, XML_ptLst);
// write ConnectorList
rTarget->startElementNS(XML_dgm, XML_cxnLst);
for (auto& rConnection : getConnections())
rConnection.writeDiagramData(rTarget);
rTarget->endElementNS(XML_dgm, XML_cxnLst);
// write BGFill
rTarget->startElementNS(XML_dgm, XML_bg);
// there is *no* export for oox::drawingml::FillProperties which we have in mpBackgroundShapeFillProperties.
// searching for 'XML_.*XML_noFill' shows that there is also a pretty direct export for FillStyle in Chart2,
// maybe that could be adapted for general use.
// But there is DrawingML::WriteFill, that needs the XShape, sax_fastparser::FSHelper and a XmlFilterBase. We
// can organize all that and then export from XShape model data.
// For The BGShape is is okay since in MSO Diagram data no shape for that exists anyways, it's just
// FillAttributes and a XShape for BG needs to exist in DrawObject model anytime anyways, see
// Diagram::createShapeHierarchyFromModel. This will also allow to use existing stuff like standard dialogs
// and more for later offering changing the Background of a Diagram.
// Note that an incarnation of BG as XShape is also needed to 'carry' the correct Size for that Diagram.
uno::Reference<drawing::XShape> xBgShape;
uno::Reference<drawing::XShapes> xGroup(rXShape, uno::UNO_QUERY);
if (xGroup.is() && 0 != xGroup->getCount())
{
// access the BGShape, it *should* always exist and be the 1st shape (to *be* in the BG)
uno::Reference<drawing::XShape> xCandidate(xGroup->getByIndex(0), uno::UNO_QUERY);
if (xCandidate.is())
{
// check comparing the DiagramDataModelID created at BackgroundSHape creation for the oox::Shape
// that got transferend to the XShape when it was created
SdrObject* pCandidate(SdrObject::getSdrObjectFromXShape(xCandidate));
if (nullptr != pCandidate && pCandidate->getDiagramDataModelID() == getBackgroundShapeModelID())
xBgShape = xCandidate;
}
}
if (xBgShape.is())
{
// if we have the BGShape as XShape, export using a temp DrawingML which uses
// the target file combined with the XmlFilterBase representing the ongoing Diagram export
DrawingML aTempML(rTarget, &rFB);
uno::Reference<beans::XPropertySet> xProps(xBgShape, uno::UNO_QUERY);
aTempML.WriteFill( xProps, xBgShape->getSize());
}
rTarget->endElementNS(XML_dgm, XML_bg);
rTarget->singleElementNS(XML_dgm, XML_whole);
// write ExtList & it's contents
// Note: I *tried* to use XML_dsp and xmlns:dsp, but these are not defined, thus
// for this case where the only relevant data is the 'relId' entzry I will allow
// to construct the XML statement by own string concatenation
rTarget->startElementNS(XML_dgm, XML_extLst);
const OUString rNsDsp(rFB.getNamespaceURL(OOX_NS(dsp)));
rTarget->startElementNS(XML_a, XML_ext, XML_uri, rNsDsp);
OUString aDspLine("<dsp:dataModelExt xmlns:dsp=\"" + rNsDsp + "\" ");
if (!getExtDrawings().empty())
{
aDspLine += "relId=\"" + getExtDrawings().front() + "\" ";
}
aDspLine += "minVer=\"" + aNsDml + "\"/>";
rTarget->write(aDspLine);
rTarget->endElementNS(XML_a, XML_ext);
rTarget->endElementNS(XML_dgm, XML_extLst);
rTarget->endElementNS(XML_dgm, XML_dataModel);
rTarget->endDocument();
}
static void addProperty(const OUString& rName,
const css::uno::Reference< css::beans::XPropertySetInfo >& xInfo,
std::vector< std::pair< OUString, css::uno::Any >>& rTarget,
@@ -95,7 +186,7 @@ static void addProperty(const OUString& rName,
rTarget.push_back(std::pair(OUString(rName), xPropSet->getPropertyValue(rName)));
}
void DiagramData::secureStyleDataFromShapeToModel(::oox::drawingml::Shape& rShape)
void DiagramData_oox::secureStyleDataFromShapeToModel(::oox::drawingml::Shape& rShape)
{
const std::vector< ShapePtr >& rChildren(rShape.getChildren());
@@ -122,7 +213,7 @@ void DiagramData::secureStyleDataFromShapeToModel(::oox::drawingml::Shape& rShap
// define target to save to
svx::diagram::PointStyle* pTarget(nullptr);
const bool bIsBackgroundShape(rShape.getDiagramDataModelID() == msBackgroundShapeModelID);
const bool bIsBackgroundShape(rShape.getDiagramDataModelID() == getBackgroundShapeModelID());
if(bIsBackgroundShape)
{
@@ -270,7 +361,7 @@ void DiagramData::secureStyleDataFromShapeToModel(::oox::drawingml::Shape& rShap
}
}
void DiagramData::secureDataFromShapeToModelAfterDiagramImport(::oox::drawingml::Shape& rRootShape)
void DiagramData_oox::secureDataFromShapeToModelAfterDiagramImport(::oox::drawingml::Shape& rRootShape)
{
const std::vector< ShapePtr >& rChildren(rRootShape.getChildren());
@@ -323,7 +414,7 @@ void DiagramData::secureDataFromShapeToModelAfterDiagramImport(::oox::drawingml:
}
}
void DiagramData::restoreStyleDataFromShapeToModel(::oox::drawingml::Shape& rShape)
void DiagramData_oox::restoreStyleDataFromShapeToModel(::oox::drawingml::Shape& rShape)
{
const std::vector< ShapePtr >& rChildren(rShape.getChildren());
@@ -351,7 +442,7 @@ void DiagramData::restoreStyleDataFromShapeToModel(::oox::drawingml::Shape& rSha
// define source to save to
svx::diagram::PointStyle* pSource(nullptr);
if(rShape.getDiagramDataModelID() == msBackgroundShapeModelID)
if(rShape.getDiagramDataModelID() == getBackgroundShapeModelID())
{
// if BackgroundShape, set BackgroundShapeStyle as source
if(maBackgroundShapeStyle)
@@ -389,7 +480,7 @@ void DiagramData::restoreStyleDataFromShapeToModel(::oox::drawingml::Shape& rSha
}
}
void DiagramData::restoreDataFromShapeToModelAfterDiagramImport(::oox::drawingml::Shape& rRootShape)
void DiagramData_oox::restoreDataFromShapeToModelAfterDiagramImport(::oox::drawingml::Shape& rRootShape)
{
const std::vector< ShapePtr >& rChildren(rRootShape.getChildren());
@@ -399,13 +490,13 @@ void DiagramData::restoreDataFromShapeToModelAfterDiagramImport(::oox::drawingml
}
}
DiagramData::DiagramData()
: svx::diagram::DiagramData()
DiagramData_oox::DiagramData_oox()
: svx::diagram::DiagramData_svx()
, mpBackgroundShapeFillProperties( std::make_shared<FillProperties>() )
{
}
DiagramData::~DiagramData()
DiagramData_oox::~DiagramData_oox()
{
}
@@ -427,18 +518,18 @@ static void Point_dump(const svx::diagram::Point& rPoint, const Shape* pShape)
<< rPoint.msModelId << ", type " << rPoint.mnXMLType);
}
void DiagramData::dump() const
void DiagramData_oox::dump() const
{
SAL_INFO("oox.drawingml", "Dgm: DiagramData # of cnx: " << maConnections.size() );
SAL_INFO("oox.drawingml", "Dgm: DiagramData_oox # of cnx: " << maConnections.size() );
for (const auto& rConnection : maConnections)
Connection_dump(rConnection);
SAL_INFO("oox.drawingml", "Dgm: DiagramData # of pt: " << maPoints.size() );
SAL_INFO("oox.drawingml", "Dgm: DiagramData_oox # of pt: " << maPoints.size() );
for (const auto& rPoint : maPoints)
Point_dump(rPoint, getOrCreateAssociatedShape(rPoint));
}
void DiagramData::buildDiagramDataModel(bool bClearOoxShapes)
void DiagramData_oox::buildDiagramDataModel(bool bClearOoxShapes)
{
if(bClearOoxShapes)
{
@@ -447,7 +538,7 @@ void DiagramData::buildDiagramDataModel(bool bClearOoxShapes)
}
// call parent
svx::diagram::DiagramData::buildDiagramDataModel(bClearOoxShapes);
svx::diagram::DiagramData_svx::buildDiagramDataModel(bClearOoxShapes);
if(bClearOoxShapes)
{
@@ -26,20 +26,21 @@
#include <rtl/ustring.hxx>
#include <svx/diagram/datamodel.hxx>
#include <svx/diagram/datamodel_svx.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
#include <oox/helper/helper.hxx>
#include <oox/token/tokens.hxx>
#include <oox/shape/ShapeFilterBase.hxx>
namespace oox::drawingml {
class DiagramData : public svx::diagram::DiagramData
class DiagramData_oox : public svx::diagram::DiagramData_svx
{
public:
typedef std::map< OUString, ShapePtr > PointShapeMap;
DiagramData();
virtual ~DiagramData();
DiagramData_oox();
virtual ~DiagramData_oox();
// creates temporary processing data from model data
virtual void buildDiagramDataModel(bool bClearOoxShapes);
@@ -54,13 +55,15 @@ public:
void restoreDataFromShapeToModelAfterDiagramImport(::oox::drawingml::Shape& rRootShape);
static void restoreDataFromModelToShapeAfterReCreation(const svx::diagram::Point& rPoint, Shape& rNewShape);
void writeDiagramData(oox::core::XmlFilterBase& rFB, sax_fastparser::FSHelperPtr& rTarget, const css::uno::Reference<css::drawing::XShape>& rXShape);
protected:
void secureStyleDataFromShapeToModel(::oox::drawingml::Shape& rShape);
void restoreStyleDataFromShapeToModel(::oox::drawingml::Shape& rShape);
private:
// The model definition, the parts *only* available in oox. Also look for already
// defined ModelData in svx::diagram::DiagramData
// defined ModelData in svx::diagram::DiagramData_svx
// - FillStyle for Diagram Background (empty constructed, may stay empty)
FillPropertiesPtr mpBackgroundShapeFillProperties;
@@ -70,9 +73,9 @@ private:
PointShapeMap maPointShapeMap;
};
// Oox-local definition of DiagramData. Doing and using this on Oox
// allows to do much less static_cast(s) - if at all from svx::diagram::DiagramData
typedef std::shared_ptr< DiagramData > OoxDiagramDataPtr;
// Oox-local definition of DiagramData_oox. Doing and using this on Oox
// allows to do much less static_cast(s) - if at all from svx::diagram::DiagramData_svx
typedef std::shared_ptr< DiagramData_oox > OoxDiagramDataPtr;
}
@@ -123,7 +123,7 @@ public:
mrPoint.mbOrgChartEnabled = rAttribs.getBool( XML_val, false );
break;
case DGM_TOKEN( resizeHandles ):
mrPoint.mnResizeHandles = rAttribs.getToken( XML_val, XML_rel );
mrPoint.msResizeHandles = rAttribs.getStringDefaulted( XML_val );
break;
default:
break;
@@ -208,7 +208,7 @@ public:
PtContext( ContextHandler2Helper const& rParent,
const AttributeList& rAttribs,
svx::diagram::Point& rPoint,
DiagramData& rDiagramData):
DiagramData_oox& rDiagramData):
ContextHandler2( rParent ),
mrPoint( rPoint ),
mrDiagramData( rDiagramData )
@@ -254,7 +254,7 @@ public:
private:
svx::diagram::Point& mrPoint;
DiagramData& mrDiagramData;
DiagramData_oox& mrDiagramData;
};
// CT_PtList
@@ -262,7 +262,7 @@ class PtListContext
: public ContextHandler2
{
public:
PtListContext( ContextHandler2Helper const & rParent, svx::diagram::Points& rPoints, DiagramData& rDiagramData) :
PtListContext( ContextHandler2Helper const & rParent, svx::diagram::Points& rPoints, DiagramData_oox& rDiagramData) :
ContextHandler2( rParent ),
mrPoints( rPoints ),
mrDiagramData( rDiagramData )
@@ -287,7 +287,7 @@ public:
private:
svx::diagram::Points& mrPoints;
DiagramData& mrDiagramData;
DiagramData_oox& mrDiagramData;
};
// CT_BackgroundFormatting
@@ -21,7 +21,7 @@
#define INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DATAMODELCONTEXT_HXX
#include <oox/core/contexthandler2.hxx>
#include "datamodel.hxx"
#include "datamodel_oox.hxx"
namespace oox::drawingml {
+62 -3
View File
@@ -26,6 +26,8 @@
#include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/xml/dom/XDocument.hpp>
#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
#include <sal/log.hxx>
#include <editeng/unoprnms.hxx>
#include <drawingml/fillproperties.hxx>
@@ -37,10 +39,16 @@
#include <svx/svdpage.hxx>
#include <oox/ppt/pptimport.hxx>
#include <comphelper/xmltools.hxx>
#include "diagramlayoutatoms.hxx"
#include "layoutatomvisitors.hxx"
#include "diagramfragmenthandler.hxx"
#include <comphelper/processfactory.hxx>
#include <com/sun/star/io/TempFile.hpp>
#ifdef DBG_UTIL
#include <osl/file.hxx>
#include <iostream>
#endif
using namespace ::com::sun::star;
@@ -175,7 +183,7 @@ void Diagram::resetOOXDomValues(svx::diagram::DomMapFlags aDomMapFlags)
}
}
bool Diagram::checkOrCreateMinimalDataDoms()
bool Diagram::checkMinimalDataDoms() const
{
if (maDiagramPRDomMap.end() == maDiagramPRDomMap.find(svx::diagram::DomMapFlag::OOXData))
return false;
@@ -192,6 +200,57 @@ bool Diagram::checkOrCreateMinimalDataDoms()
return true;
}
void Diagram::tryToCreateMissingDataDoms(oox::core::XmlFilterBase& rFB, const css::uno::Reference<css::drawing::XShape>& rXRootShape)
{
// internal testing: allow to force to always recreate
static bool bForceAlwaysReCreate(false);
// check if activated, return if not to stay compatible for now
static bool bReCreateDiagramDataDoms(nullptr != std::getenv("ACTIVATE_RECREATE_DIAGRAM_DATADOMS"));
#ifdef DBG_UTIL
std::cout << "DiagramReCreate: always==" << bForceAlwaysReCreate << ",bReCreate==" << bReCreateDiagramDataDoms << std::endl;
#endif
if (!bForceAlwaysReCreate && !bReCreateDiagramDataDoms)
return;
if (bForceAlwaysReCreate || maDiagramPRDomMap.end() == maDiagramPRDomMap.find(svx::diagram::DomMapFlag::OOXData))
{
// re-create OOXData DomFile from model data
#ifdef DBG_UTIL
std::cout << "DiagramReCreate: creating DomMapFlag::OOXData" << std::endl;
#endif
uno::Reference< io::XTempFile > xTempFile = io::TempFile::create(comphelper::getProcessComponentContext());
uno::Reference< io::XOutputStream > xOutput = xTempFile->getOutputStream();
if (xOutput)
{
sax_fastparser::FSHelperPtr aFS = std::make_shared<sax_fastparser::FastSerializerHelper>(xOutput, true);
getData()->writeDiagramData(rFB, aFS, rXRootShape);
xOutput->flush();
// this call is *important*, without it xDocBuilder->parse below fails and some strange
// and wrong assertion gets thrown in ~FastSerializerHelper that shall get called
xOutput->closeOutput();
uno::Reference<xml::dom::XDocumentBuilder> xDocBuilder(xml::dom::DocumentBuilder::create(comphelper::getProcessComponentContext()));
if (xDocBuilder)
{
uno::Reference<xml::dom::XDocument> xInstance = xDocBuilder->parse(xTempFile->getInputStream());
if (xInstance)
{
maDiagramPRDomMap[svx::diagram::DomMapFlag::OOXData] <<= xInstance;
}
}
#ifdef DBG_UTIL
osl::File::move(xTempFile->getUri(), "file:///home/alg/Downloads/tonne/test.xml");
#endif
}
}
// more to do...
}
using ShapePairs
= std::map<std::shared_ptr<drawingml::Shape>, css::uno::Reference<css::drawing::XShape>>;
@@ -328,7 +387,7 @@ void loadDiagram( ShapePtr const & pShape,
{
DiagramPtr pDiagram = std::make_shared<Diagram>();
OoxDiagramDataPtr pData = std::make_shared<DiagramData>();
OoxDiagramDataPtr pData = std::make_shared<DiagramData_oox>();
pDiagram->setData( pData );
DiagramLayoutPtr pLayout = std::make_shared<DiagramLayout>(*pDiagram);
+3 -2
View File
@@ -26,7 +26,7 @@
#include <rtl/ustring.hxx>
#include "datamodel.hxx"
#include "datamodel_oox.hxx"
#include <oox/drawingml/shape.hxx>
namespace com::sun::star {
@@ -152,7 +152,8 @@ public:
void resetOOXDomValues(svx::diagram::DomMapFlags aDomMapFlags);
// check if mandatory DiagramDomS exist (or can be created)
bool checkOrCreateMinimalDataDoms();
bool checkMinimalDataDoms() const;
void tryToCreateMissingDataDoms(oox::core::XmlFilterBase& rFB, const com::sun::star::uno::Reference<css::drawing::XShape>& rXRootShape);
private:
// This contains groups of shapes: automatic font size is the same in each group.
@@ -18,7 +18,7 @@
*/
#include "diagramdefinitioncontext.hxx"
#include "datamodel.hxx"
#include "datamodel_oox.hxx"
#include "datamodelcontext.hxx"
#include "layoutnodecontext.hxx"
#include <oox/helper/attributelist.hxx>
@@ -78,10 +78,10 @@ DiagramDefinitionContext::onCreateContext( ::sal_Int32 aElement,
// TODO, does not matter for the UI. skip.
return nullptr;
case DGM_TOKEN( sampData ):
mpLayout->getSampData() = std::make_shared<DiagramData>();
mpLayout->getSampData() = std::make_shared<DiagramData_oox>();
return new DataModelContext( *this, mpLayout->getSampData() );
case DGM_TOKEN( styleData ):
mpLayout->getStyleData() = std::make_shared<DiagramData>();
mpLayout->getStyleData() = std::make_shared<DiagramData_oox>();
return new DataModelContext( *this, mpLayout->getStyleData() );
case DGM_TOKEN( cat ):
case DGM_TOKEN( catLst ):
+18 -7
View File
@@ -17,7 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "diagramhelper.hxx"
#include <oox/drawingml/diagram/diagramhelper.hxx>
#include "diagram.hxx"
#include <basegfx/matrix/b2dhommatrix.hxx>
@@ -29,6 +29,7 @@
#include <comphelper/processfactory.hxx>
#include <oox/drawingml/themefragmenthandler.hxx>
#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <utility>
using namespace ::com::sun::star;
@@ -110,7 +111,7 @@ void AdvancedDiagramHelper::reLayout(SdrObjGroup& rTarget)
if(UseDiagramThemeData() || !isSelfCreated())
xFilter->setCurrentTheme(getOrCreateThemePtr(xFilter));
css::uno::Reference< css::lang::XComponent > aComponentModel( rUnoModel, uno::UNO_QUERY );
uno::Reference< css::lang::XComponent > aComponentModel( rUnoModel, uno::UNO_QUERY );
xFilter->setTargetDocument(aComponentModel);
// set DiagramFontHeights
@@ -239,7 +240,9 @@ void AdvancedDiagramHelper::TextInformationChange(const OUString& rDiagramDataMo
// still reset GrabBag at Associated SdrObjGroup object. There are no "OOX.*"
// entries anymore, but others like "mso-rotation-angle" and others
mpAssociatedSdrObjGroup->SetGrabBagItem(uno::Any(uno::Sequence<beans::PropertyValue>()));
uno::Reference<beans::XPropertySet> xPropSet(mxGroupShape, uno::UNO_QUERY);
if (xPropSet->getPropertySetInfo()->hasPropertyByName(u"InteropGrabBag"_ustr))
xPropSet->setPropertyValue(u"InteropGrabBag"_ustr, uno::Any(uno::Sequence<beans::PropertyValue>()));
}
}
@@ -263,9 +266,9 @@ void AdvancedDiagramHelper::applyDiagramDataState(const svx::diagram::DiagramDat
mpDiagramPtr->getData()->applyDiagramDataState(rState);
}
void AdvancedDiagramHelper::doAnchor(SdrObjGroup& rTarget, ::oox::drawingml::Shape& rRootShape)
void AdvancedDiagramHelper::doAnchor(uno::Reference<drawing::XShape>& rTarget, ::oox::drawingml::Shape& rRootShape)
{
if(!mpDiagramPtr)
if(!mpDiagramPtr || !rTarget)
{
return;
}
@@ -325,12 +328,20 @@ uno::Any AdvancedDiagramHelper::getOOXDomValue(svx::diagram::DomMapFlag aDomMapF
return uno::Any();
}
bool AdvancedDiagramHelper::checkOrCreateMinimalDataDoms()
bool AdvancedDiagramHelper::checkMinimalDataDoms() const
{
if (!mpDiagramPtr)
return false;
return mpDiagramPtr->checkOrCreateMinimalDataDoms();
return mpDiagramPtr->checkMinimalDataDoms();
}
void AdvancedDiagramHelper::tryToCreateMissingDataDoms(oox::core::XmlFilterBase& rFB)
{
if (!mpDiagramPtr)
return;
mpDiagramPtr->tryToCreateMissingDataDoms(rFB, mxGroupShape);
}
}
@@ -909,7 +909,7 @@ bool ConditionAtom::getDecision(const svx::diagram::Point* pPresPoint) const
// point, ask the parent.
OUString aParent = navigate(mrLayoutNode, svx::diagram::TypeConstant::XML_presParOf, pPresPoint->msModelId,
/*bSourceToDestination*/ false);
DiagramData::PointNameMap& rPointNameMap
DiagramData_oox::PointNameMap& rPointNameMap
= mrLayoutNode.getDiagram().getData()->getPointNameMap();
auto it = rPointNameMap.find(aParent);
if (it != rPointNameMap.end())
@@ -1075,9 +1075,9 @@ bool HasCustomText(const ShapePtr& rShape, LayoutNode& rLayoutNode)
{
const PresPointShapeMap& rPresPointShapeMap
= rLayoutNode.getDiagram().getLayout()->getPresPointShapeMap();
const DiagramData::StringMap& rPresOfNameMap
const DiagramData_oox::StringMap& rPresOfNameMap
= rLayoutNode.getDiagram().getData()->getPresOfNameMap();
const DiagramData::PointNameMap& rPointNameMap
const DiagramData_oox::PointNameMap& rPointNameMap
= rLayoutNode.getDiagram().getData()->getPointNameMap();
// Get the first presentation node of the shape.
const svx::diagram::Point* pPresNode = nullptr;
@@ -1098,7 +1098,7 @@ bool HasCustomText(const ShapePtr& rShape, LayoutNode& rLayoutNode)
{
for (const auto& rPair : itPresToData->second)
{
const DiagramData::SourceIdAndDepth& rItem = rPair.second;
const DiagramData_oox::SourceIdAndDepth& rItem = rPair.second;
auto it = rPointNameMap.find(rItem.msSourceId);
if (it != rPointNameMap.end())
{
@@ -1872,7 +1872,7 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const svx::diagram::Point*
<< "\", modelId \"" << pPresNode->msModelId << "\"");
// have the presentation node - now, need the actual data node:
const DiagramData::StringMap::const_iterator aNodeName = mrDgm.getData()->getPresOfNameMap().find(
const DiagramData_oox::StringMap::const_iterator aNodeName = mrDgm.getData()->getPresOfNameMap().find(
pPresNode->msModelId);
if( aNodeName != mrDgm.getData()->getPresOfNameMap().end() )
{
@@ -1886,10 +1886,10 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const svx::diagram::Point*
for (const auto& rPair : aNodeName->second)
{
const DiagramData::SourceIdAndDepth& rItem = rPair.second;
DiagramData::PointNameMap& rMap = mrDgm.getData()->getPointNameMap();
const DiagramData_oox::SourceIdAndDepth& rItem = rPair.second;
DiagramData_oox::PointNameMap& rMap = mrDgm.getData()->getPointNameMap();
// pPresNode is the presentation node of the aDataNode2 data node.
DiagramData::PointNameMap::const_iterator aDataNode2 = rMap.find(rItem.msSourceId);
DiagramData_oox::PointNameMap::const_iterator aDataNode2 = rMap.find(rItem.msSourceId);
if (aDataNode2 == rMap.end())
{
//busted, skip it
@@ -109,7 +109,7 @@ void LayoutAtomVisitorBase::visit(LayoutNode& rAtom)
// stop processing if it's not a child of previous LayoutNode
const DiagramData::PointsNameMap::const_iterator aDataNode
const DiagramData_oox::PointsNameMap::const_iterator aDataNode
= mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
|| mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
@@ -158,7 +158,7 @@ void ShallowPresNameVisitor::visit(ForEachAtom& rAtom)
void ShallowPresNameVisitor::visit(LayoutNode& rAtom)
{
DiagramData::PointsNameMap::const_iterator aDataNode =
DiagramData_oox::PointsNameMap::const_iterator aDataNode =
mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
if( aDataNode != mrDgm.getData()->getPointsPresNameMap().end() )
mnCnt = std::max(mnCnt,
@@ -54,7 +54,7 @@ void ShapeCreationVisitor::visit(LayoutNode& rAtom)
// stop processing if it's not a child of previous LayoutNode
const DiagramData::PointsNameMap::const_iterator aDataNode
const DiagramData_oox::PointsNameMap::const_iterator aDataNode
= mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
|| mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
@@ -218,7 +218,7 @@ void ShapeLayoutingVisitor::visit(LayoutNode& rAtom)
// stop processing if it's not a child of previous LayoutNode
const DiagramData::PointsNameMap::const_iterator aDataNode
const DiagramData_oox::PointsNameMap::const_iterator aDataNode
= mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
|| mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
+4 -6
View File
@@ -54,8 +54,8 @@
#include <oox/mathml/imexport.hxx>
#include <oox/mathml/importutils.hxx>
#include <oox/token/properties.hxx>
#include "diagram/datamodel.hxx"
#include "diagram/diagramhelper.hxx"
#include "diagram/datamodel_oox.hxx"
#include <oox/drawingml/diagram/diagramhelper.hxx>
#include <comphelper/classids.hxx>
#include <comphelper/propertysequence.hxx>
@@ -274,11 +274,9 @@ void Shape::propagateDiagramHelper()
// Propagate collected Diagram data to data holder
if (FRAMETYPE_DIAGRAM == meFrameType && nullptr != mpDiagramHelper)
{
SdrObjGroup* pAnchorObj = dynamic_cast<SdrObjGroup*>(SdrObject::getSdrObjectFromXShape(mxShape));
if(pAnchorObj)
if (mxShape)
{
mpDiagramHelper->doAnchor(*pAnchorObj, *this);
mpDiagramHelper->doAnchor(mxShape, *this);
mpDiagramHelper = nullptr;
}
}
+18 -6
View File
@@ -19,6 +19,7 @@
#include <config_features.h>
#include <oox/drawingml/diagram/diagramhelper.hxx>
#include <config_folders.h>
#include <rtl/bootstrap.hxx>
#include <sal/log.hxx>
@@ -6807,9 +6808,9 @@ OString DrawingML::WriteWdpPicture( const OUString& rFileId, const Sequence< sal
return OUStringToOString(aId, RTL_TEXTENCODING_UTF8);
}
bool DrawingML::PrepareToWriteAsDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape)
bool DrawingML::PrepareToWriteAsDiagram(const css::uno::Reference<css::drawing::XShape>& rXRootShape)
{
SdrObject* pObj(SdrObject::getSdrObjectFromXShape(rXShape));
SdrObject* pObj(SdrObject::getSdrObjectFromXShape(rXRootShape));
if (nullptr == pObj)
return false;
@@ -6819,7 +6820,15 @@ bool DrawingML::PrepareToWriteAsDiagram(const css::uno::Reference<css::drawing::
if (!rIDiagramHelper)
return false;
if (!rIDiagramHelper->checkOrCreateMinimalDataDoms())
AdvancedDiagramHelper* pAdvancedDiagramHelper = static_cast<AdvancedDiagramHelper*>(rIDiagramHelper.get());
if (nullptr == pAdvancedDiagramHelper)
return false;
// try to re-create (if needed is decided there)
pAdvancedDiagramHelper->tryToCreateMissingDataDoms(*GetFB());
if (!pAdvancedDiagramHelper->checkMinimalDataDoms())
return false;
return true;
@@ -6827,9 +6836,6 @@ bool DrawingML::PrepareToWriteAsDiagram(const css::uno::Reference<css::drawing::
void DrawingML::WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape, sal_Int32 nDiagramId, sal_Int32 nShapeId)
{
if (!PrepareToWriteAsDiagram(rXShape))
return;
SdrObject* pObj = SdrObject::getSdrObjectFromXShape(rXShape);
assert(pObj && "no SdrObject");
assert(pObj->isDiagram() && "is no Diagram");
@@ -6837,6 +6843,12 @@ void DrawingML::WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rX
const std::shared_ptr< svx::diagram::IDiagramHelper >& rIDiagramHelper(pObj->getDiagramHelper());
assert(rIDiagramHelper && "has no DiagramHelper");
const AdvancedDiagramHelper* pAdvancedDiagramHelper = static_cast<AdvancedDiagramHelper*>(rIDiagramHelper.get());
assert(pAdvancedDiagramHelper && "has no DiagramHelper");
if (!pAdvancedDiagramHelper->checkMinimalDataDoms())
return;
// get/check mandatory DomS
uno::Reference<xml::dom::XDocument> dataDom;
rIDiagramHelper->getOOXDomValue(svx::diagram::DomMapFlag::OOXData) >>= dataDom;
+1 -1
View File
@@ -2369,7 +2369,7 @@ void PowerPointExport::WriteShapeTree(const FSHelperPtr& pFS, PageType ePageType
bool bIsDiagram(nullptr != pDiagramCandidate && pDiagramCandidate->isDiagram());
// check if export as Diagram is possible
if (bIsDiagram && !oox::drawingml::DrawingML::PrepareToWriteAsDiagram(mXShape))
if (bIsDiagram && !aDML.PrepareToWriteAsDiagram(mXShape))
bIsDiagram = false;
if (bIsDiagram)
+5 -5
View File
@@ -5149,6 +5149,7 @@ include/oox/drawingml/clrscheme.hxx
include/oox/drawingml/color.hxx
include/oox/drawingml/connectorshapecontext.hxx
include/oox/drawingml/diagram/diagram.hxx
include/oox/drawingml/diagram/diagramhelper.hxx
include/oox/drawingml/drawingmltypes.hxx
include/oox/drawingml/graphicshapecontext.hxx
include/oox/drawingml/shape.hxx
@@ -5673,7 +5674,7 @@ include/svx/sdgmoitm.hxx
include/svx/sdmetitm.hxx
include/svx/sdooitm.hxx
include/svx/sdprcitm.hxx
include/svx/diagram/datamodel.hxx
include/svx/diagram/datamodel_svx.hxx
include/svx/diagram/IDiagramHelper.hxx
include/svx/sdr/animation/animationstate.hxx
include/svx/sdr/animation/objectanimator.hxx
@@ -6830,10 +6831,9 @@ oox/source/drawingml/customshapegeometry.cxx
oox/source/drawingml/customshapeproperties.cxx
oox/source/drawingml/diagram/constraintlistcontext.cxx
oox/source/drawingml/diagram/constraintlistcontext.hxx
oox/source/drawingml/diagram/datamodel.cxx
oox/source/drawingml/diagram/datamodel.hxx
oox/source/drawingml/diagram/datamodel_oox.cxx
oox/source/drawingml/diagram/datamodel_oox.hxx
oox/source/drawingml/diagram/diagramhelper.cxx
oox/source/drawingml/diagram/diagramhelper.hxx
oox/source/drawingml/diagram/datamodelcontext.cxx
oox/source/drawingml/diagram/datamodelcontext.hxx
oox/source/drawingml/diagram/diagram.cxx
@@ -11121,7 +11121,7 @@ svx/source/customshapes/EnhancedCustomShapeGeometry.cxx
svx/source/customshapes/EnhancedCustomShapeHandle.cxx
svx/source/customshapes/EnhancedCustomShapeHandle.hxx
svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx
svx/source/diagram/datamodel.cxx
svx/source/diagram/datamodel_svx.cxx
svx/source/diagram/IDiagramHelper.cxx
svx/source/dialog/ClassificationDialog.cxx
svx/source/dialog/ClassificationEditView.cxx
+1 -1
View File
@@ -117,7 +117,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/customshapes/EnhancedCustomShapeFunctionParser \
svx/source/customshapes/EnhancedCustomShapeGeometry \
svx/source/customshapes/EnhancedCustomShapeTypeNames \
svx/source/diagram/datamodel \
svx/source/diagram/datamodel_svx \
svx/source/diagram/IDiagramHelper \
svx/source/dialog/dialmgr \
svx/source/dialog/dlgutil \
+18 -9
View File
@@ -410,7 +410,7 @@ IDiagramHelper::IDiagramHelper(bool bSelfCreated)
, mbUseDiagramModelData(true)
, mbForceThemePtrRecreation(false)
, mbSelfCreated(bSelfCreated)
, mpAssociatedSdrObjGroup(nullptr)
, mxGroupShape()
{
}
@@ -418,26 +418,35 @@ IDiagramHelper::~IDiagramHelper() {}
void IDiagramHelper::disconnectFromSdrObjGroup()
{
if (nullptr != mpAssociatedSdrObjGroup)
SdrObjGroup* pGroupObject(dynamic_cast<SdrObjGroup*>(SdrObject::getSdrObjectFromXShape(mxGroupShape)));
if (nullptr != pGroupObject)
{
auto const p = mpAssociatedSdrObjGroup;
mpAssociatedSdrObjGroup = nullptr;
p->mp_DiagramHelper.reset();
mxGroupShape.clear();
pGroupObject->mp_DiagramHelper.reset();
}
}
void IDiagramHelper::connectToSdrObjGroup(SdrObjGroup& rTarget)
void IDiagramHelper::connectToSdrObjGroup(com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rTarget)
{
SdrObjGroup* pGroupObject(nullptr);
if (pGroupObject && mxGroupShape && rTarget == mxGroupShape)
{
pGroupObject = dynamic_cast<SdrObjGroup*>(SdrObject::getSdrObjectFromXShape(mxGroupShape));
if (pGroupObject != nullptr && pGroupObject->mp_DiagramHelper.get() == this)
{
if (mpAssociatedSdrObjGroup == &rTarget && rTarget.mp_DiagramHelper.get() == this)
// connection already established
return;
}
}
// ensure unconnect if already connected
disconnectFromSdrObjGroup();
// connect to target
mpAssociatedSdrObjGroup = &rTarget;
rTarget.mp_DiagramHelper.reset(this);
mxGroupShape = rTarget;
pGroupObject = dynamic_cast<SdrObjGroup*>(SdrObject::getSdrObjectFromXShape(mxGroupShape));
if (nullptr != pGroupObject)
pGroupObject->mp_DiagramHelper.reset(this);;
}
void IDiagramHelper::AddAdditionalVisualization(const SdrObjGroup& rTarget, SdrHdlList& rHdlList)
@@ -21,14 +21,41 @@
#include <algorithm>
#include <fstream>
#include <svx/diagram/datamodel.hxx>
#include <svx/diagram/datamodel_svx.hxx>
#include <svx/svdoutl.hxx>
#include <comphelper/xmltools.hxx>
#include <sal/log.hxx>
#include <utility>
#include <sax/fastattribs.hxx>
using namespace ::oox;
namespace svx::diagram {
namespace {
void addTypeConstantToFastAttributeList(TypeConstant aTypeConstant, rtl::Reference<sax_fastparser::FastAttributeList>& rAttributeList)
{
if (TypeConstant::XML_none != aTypeConstant)
{
switch (aTypeConstant)
{
case TypeConstant::XML_type: rAttributeList->add(XML_type, "Type"); break;
case TypeConstant::XML_asst: rAttributeList->add(XML_type, "asst"); break;
case TypeConstant::XML_doc: rAttributeList->add(XML_type, "doc"); break;
case TypeConstant::XML_node: /* XML_node is default, no need to write */ break;
case TypeConstant::XML_norm: rAttributeList->add(XML_type, "norm"); break;
case TypeConstant::XML_parOf: rAttributeList->add(XML_type, "parOf"); break;
case TypeConstant::XML_parTrans: rAttributeList->add(XML_type, "parTrans"); break;
case TypeConstant::XML_pres: rAttributeList->add(XML_type, "pres"); break;
case TypeConstant::XML_presOf: rAttributeList->add(XML_type, "presOf"); break;
case TypeConstant::XML_presParOf: rAttributeList->add(XML_type, "presParOf"); break;
case TypeConstant::XML_rel: rAttributeList->add(XML_type, "rel"); break;
case TypeConstant::XML_sibTrans: rAttributeList->add(XML_type, "sibTrans"); break;
default: break; // XML_none
}
}
}}
Connection::Connection()
: mnXMLType( XML_none )
, mnSourceOrder( 0 )
@@ -36,6 +63,26 @@ Connection::Connection()
{
}
void Connection::writeDiagramData(sax_fastparser::FSHelperPtr& rTarget)
{
if (!rTarget)
return;
rtl::Reference<sax_fastparser::FastAttributeList> pAttributeList(sax_fastparser::FastSerializerHelper::createAttrList());
addTypeConstantToFastAttributeList(mnXMLType, pAttributeList);
if (!msModelId.isEmpty()) pAttributeList->add(XML_modelId, msModelId);
if (!msSourceId.isEmpty()) pAttributeList->add(XML_srcId, msSourceId);
if (!msDestId.isEmpty()) pAttributeList->add(XML_destId, msDestId);
if (!msPresId.isEmpty()) pAttributeList->add(XML_presId, msPresId);
if (!msSibTransId.isEmpty()) pAttributeList->add(XML_sibTransId, msSibTransId);
if (!msParTransId.isEmpty()) pAttributeList->add(XML_parTransId, msParTransId);
if (0 != mnSourceOrder) pAttributeList->add(XML_srcOrd, OUString::number(mnSourceOrder));
if (0 != mnDestOrder) pAttributeList->add(XML_destOrd, OUString::number(mnDestOrder));
rTarget->singleElementNS(XML_dgm, XML_cxn, pAttributeList);
}
Point::Point()
: msTextBody(std::make_shared< TextBody >())
, msPointStylePtr(std::make_shared< PointStyle >())
@@ -43,7 +90,6 @@ Point::Point()
, mnMaxChildren(-1)
, mnPreferredChildren(-1)
, mnDirection(XML_norm)
, mnResizeHandles(XML_rel)
, mnCustomAngle(-1)
, mnPercentageNeighbourWidth(-1)
, mnPercentageNeighbourHeight(-1)
@@ -67,15 +113,151 @@ Point::Point()
{
}
DiagramData::DiagramData()
void Point::writeDiagramData(sax_fastparser::FSHelperPtr& rTarget)
{
if (!rTarget)
return;
rtl::Reference<sax_fastparser::FastAttributeList> pAttributeList(sax_fastparser::FastSerializerHelper::createAttrList());
pAttributeList->add(XML_modelId, msModelId);
addTypeConstantToFastAttributeList(mnXMLType, pAttributeList);
if (!msCnxId.isEmpty())
pAttributeList->add(XML_cxnId, msCnxId);
rTarget->startElementNS(XML_dgm, XML_pt, pAttributeList);
pAttributeList->clear();
if (!msColorTransformCategoryId.isEmpty()) pAttributeList->add(XML_csCatId, msColorTransformCategoryId);
if (!msColorTransformTypeId.isEmpty()) pAttributeList->add(XML_csTypeId, msColorTransformTypeId);
if (!msLayoutCategoryId.isEmpty()) pAttributeList->add(XML_loCatId, msLayoutCategoryId);
if (!msLayoutTypeId.isEmpty()) pAttributeList->add(XML_loTypeId, msLayoutTypeId);
if (!msPlaceholderText.isEmpty()) pAttributeList->add(XML_phldrT, msPlaceholderText);
if (!msPresentationAssociationId.isEmpty()) pAttributeList->add(XML_presAssocID, msPresentationAssociationId);
if (!msPresentationLayoutName.isEmpty()) pAttributeList->add(XML_presName, msPresentationLayoutName);
if (!msPresentationLayoutStyleLabel.isEmpty()) pAttributeList->add(XML_presStyleLbl, msPresentationLayoutStyleLabel);
if (!msQuickStyleCategoryId.isEmpty()) pAttributeList->add(XML_qsCatId, msQuickStyleCategoryId);
if (!msQuickStyleTypeId.isEmpty()) pAttributeList->add(XML_qsTypeId, msQuickStyleTypeId);
if (-1 != mnCustomAngle) pAttributeList->add(XML_custAng, OUString::number(mnCustomAngle));
if (-1 != mnPercentageNeighbourWidth) pAttributeList->add(XML_custLinFactNeighborX, OUString::number(mnPercentageNeighbourWidth));
if (-1 != mnPercentageNeighbourHeight) pAttributeList->add(XML_custLinFactNeighborY, OUString::number(mnPercentageNeighbourHeight));
if (-1 != mnPercentageOwnWidth) pAttributeList->add(XML_custLinFactX, OUString::number(mnPercentageOwnWidth));
if (-1 != mnPercentageOwnHeight) pAttributeList->add(XML_custLinFactY, OUString::number(mnPercentageOwnHeight));
if (-1 != mnIncludeAngleScale) pAttributeList->add(XML_custRadScaleInc, OUString::number(mnIncludeAngleScale));
if (-1 != mnRadiusScale) pAttributeList->add(XML_custRadScaleRad, OUString::number(mnRadiusScale));
if (-1 != mnWidthScale) pAttributeList->add(XML_custScaleX, OUString::number(mnWidthScale));
if (-1 != mnHeightScale) pAttributeList->add(XML_custScaleY, OUString::number(mnHeightScale));
if (-1 != mnWidthOverride) pAttributeList->add(XML_custSzX, OUString::number(mnWidthOverride));
if (-1 != mnHeightOverride) pAttributeList->add(XML_custSzY, OUString::number(mnHeightOverride));
if (-1 != mnLayoutStyleCount) pAttributeList->add(XML_presStyleCnt, OUString::number(mnLayoutStyleCount));
if (-1 != mnLayoutStyleIndex) pAttributeList->add(XML_presStyleIdx, OUString::number(mnLayoutStyleIndex));
static constexpr OUString aStrTrue = u"1"_ustr; // this uses "1", not "true"
if (true == mbCoherent3DOffset) pAttributeList->add(XML_coherent3DOff, aStrTrue);
if (true == mbCustomHorizontalFlip) pAttributeList->add(XML_custFlipHor, aStrTrue);
if (true == mbCustomVerticalFlip) pAttributeList->add(XML_custFlipVert, aStrTrue);
if (true == mbCustomText) pAttributeList->add(XML_custT, aStrTrue);
if (true == mbIsPlaceholder) pAttributeList->add(XML_phldr, aStrTrue);
const bool bNeed_presLayoutVars(mbBulletEnabled
|| -1 != mnMaxChildren
|| -1 != mnPreferredChildren
|| XML_norm != mnDirection
|| moHierarchyBranch.has_value()
|| mbOrgChartEnabled
|| !msResizeHandles.isEmpty());
if (bNeed_presLayoutVars)
{
rTarget->startElementNS(XML_dgm, XML_prSet, pAttributeList);
rTarget->startElementNS(XML_dgm, XML_presLayoutVars);
if (mbBulletEnabled)
rTarget->singleElementNS(XML_dgm, XML_bulletEnabled, XML_val, aStrTrue);
if (-1 != mnMaxChildren)
rTarget->singleElementNS(XML_dgm, XML_chMax, XML_val, OUString::number(mnMaxChildren));
if (-1 != mnPreferredChildren)
rTarget->singleElementNS(XML_dgm, XML_chPref, XML_val, OUString::number(mnPreferredChildren));
if (XML_norm != mnDirection)
rTarget->singleElementNS(XML_dgm, XML_dir, XML_val, OString::number(mnDirection));
if (moHierarchyBranch.has_value())
rTarget->singleElementNS(XML_dgm, XML_hierBranch, XML_val, OString::number(moHierarchyBranch.value()));
if (mbOrgChartEnabled)
rTarget->singleElementNS(XML_dgm, XML_orgChart, XML_val, aStrTrue);
if (!msResizeHandles.isEmpty())
rTarget->singleElementNS(XML_dgm, XML_resizeHandles, XML_val, msResizeHandles);
rTarget->endElementNS(XML_dgm, XML_presLayoutVars);
rTarget->endElementNS(XML_dgm, XML_prSet);
}
else
rTarget->singleElementNS(XML_dgm, XML_prSet, pAttributeList);
rTarget->singleElementNS(XML_dgm, XML_spPr);
bool bWriteText(TypeConstant::XML_parTrans == mnXMLType || TypeConstant::XML_sibTrans == mnXMLType);
if (!bWriteText && "textNode" == msPresentationLayoutName)
bWriteText = true;
const bool bTextEmpty(msTextBody->msText.isEmpty());
if (!bWriteText && !bTextEmpty)
bWriteText = true;
if(bWriteText)
{
// for writing text we would need to use the XShape containing it, and DrawingML::WriteText.
// we *could* find the XShape that is referencing this svx::diagram::Point, the text should
// be set there.
// For now, just make a rough export to get this started. This will have to be enhanced in
// the future, either by using XShape or by implementing exporting the raw MSO XML data we
// have here at the mnodel from import - which implies that that is what gets changed when
// text or textAttributes get changed, plus a re-creation of the XShapes in the GroupObject
rTarget->startElementNS(XML_dgm, XML_t);
rTarget->singleElementNS(XML_a, XML_bodyPr);
rTarget->singleElementNS(XML_a, XML_lstStyle);
rTarget->startElementNS(XML_a, XML_p);
if (bTextEmpty)
{
rTarget->singleElementNS(XML_a, XML_endParaRPr, XML_lang, "en-US");
}
else
{
rTarget->startElementNS(XML_a, XML_r);
rTarget->singleElementNS(XML_a, XML_rPr, XML_lang, "de-DE", XML_dirty, "0", XML_smtClean, "0");
rTarget->startElementNS(XML_a, XML_t);
rTarget->write(msTextBody->msText);
rTarget->endElementNS(XML_a, XML_t);
rTarget->endElementNS(XML_a, XML_r);
rTarget->singleElementNS(XML_a, XML_endParaRPr, XML_lang, "en-US", XML_dirty, "0");
}
rTarget->endElementNS(XML_a, XML_p);
rTarget->endElementNS(XML_dgm, XML_t);
}
rTarget->endElementNS(XML_dgm, XML_pt);
}
DiagramData_svx::DiagramData_svx()
{
}
DiagramData::~DiagramData()
DiagramData_svx::~DiagramData_svx()
{
}
const Point* DiagramData::getRootPoint() const
const Point* DiagramData_svx::getRootPoint() const
{
for (const auto & aCurrPoint : maPoints)
if (aCurrPoint.mnXMLType == TypeConstant::XML_doc)
@@ -85,7 +267,7 @@ const Point* DiagramData::getRootPoint() const
return nullptr;
}
OUString DiagramData::getString() const
OUString DiagramData_svx::getString() const
{
OUStringBuffer aBuf;
const Point* pPoint = getRootPoint();
@@ -93,7 +275,7 @@ OUString DiagramData::getString() const
return aBuf.makeStringAndClear();
}
DomMapFlags DiagramData::removeDiagramNode(const OUString& rNodeId)
DomMapFlags DiagramData_svx::removeDiagramNode(const OUString& rNodeId)
{
DomMapFlags aRetval;
@@ -143,8 +325,9 @@ DomMapFlags DiagramData::removeDiagramNode(const OUString& rNodeId)
// prepare retval, OOXData and OOXLayout is changed
aRetval.push_back(DomMapFlag::OOXData);
aRetval.push_back(DomMapFlag::OOXDataRels);
aRetval.push_back(DomMapFlag::OOXLayout);
// aRetval.push_back(DomMapFlag::OOXDrawing);
// aRetval.push_back(DomMapFlag::OOXDataRels);
// aRetval.push_back(DomMapFlag::OOXLayout);
return aRetval;
}
@@ -155,14 +338,14 @@ DiagramDataState::DiagramDataState(Connections aConnections, Points aPoints)
{
}
DiagramDataStatePtr DiagramData::extractDiagramDataState() const
DiagramDataStatePtr DiagramData_svx::extractDiagramDataState() const
{
// Just copy all Connections && Points. The shared_ptr data in
// Point-entries is no problem, it just continues exiting shared
return std::make_shared< DiagramDataState >(maConnections, maPoints);
}
void DiagramData::applyDiagramDataState(const DiagramDataStatePtr& rState)
void DiagramData_svx::applyDiagramDataState(const DiagramDataStatePtr& rState)
{
if(rState)
{
@@ -176,7 +359,7 @@ void DiagramData::applyDiagramDataState(const DiagramDataStatePtr& rState)
}
}
void DiagramData::getChildrenString(
void DiagramData_svx::getChildrenString(
OUStringBuffer& rBuf,
const svx::diagram::Point* pPoint,
sal_Int32 nLevel) const
@@ -209,7 +392,7 @@ void DiagramData::getChildrenString(
getChildrenString(rBuf, pChild, nLevel + 1);
}
std::vector<std::pair<OUString, OUString>> DiagramData::getChildren(const OUString& rParentId) const
std::vector<std::pair<OUString, OUString>> DiagramData_svx::getChildren(const OUString& rParentId) const
{
const OUString sModelId = rParentId.isEmpty() ? getRootPoint()->msModelId : rParentId;
std::vector<std::pair<OUString, OUString>> aChildren;
@@ -233,7 +416,7 @@ std::vector<std::pair<OUString, OUString>> DiagramData::getChildren(const OUStri
return aChildren;
}
std::pair<OUString, DomMapFlags> DiagramData::addDiagramNode(const OUString& rText)
std::pair<OUString, DomMapFlags> DiagramData_svx::addDiagramNode(const OUString& rText)
{
DomMapFlags aRetval;
const svx::diagram::Point& rDataRoot = *getRootPoint();
@@ -287,13 +470,14 @@ std::pair<OUString, DomMapFlags> DiagramData::addDiagramNode(const OUString& rTe
// prepare retval, OOXData and OOXLayout is changed
aRetval.push_back(DomMapFlag::OOXData);
aRetval.push_back(DomMapFlag::OOXDataRels);
aRetval.push_back(DomMapFlag::OOXLayout);
// aRetval.push_back(DomMapFlag::OOXDrawing);
// aRetval.push_back(DomMapFlag::OOXDataRels);
// aRetval.push_back(DomMapFlag::OOXLayout);
return std::make_pair(sNewNodeId, aRetval);
}
void DiagramData::addConnection(svx::diagram::TypeConstant nType, const OUString& sSourceId, const OUString& sDestId)
void DiagramData_svx::addConnection(svx::diagram::TypeConstant nType, const OUString& sSourceId, const OUString& sDestId)
{
sal_Int32 nMaxOrd = -1;
for (const auto& aCxn : maConnections)
@@ -348,7 +532,7 @@ static sal_Int32 calcDepth( std::u16string_view rNodeName,
return 0;
}
void DiagramData::buildDiagramDataModel(bool /*bClearOoxShapes*/)
void DiagramData_svx::buildDiagramDataModel(bool /*bClearOoxShapes*/)
{
// build name-object maps
maPointNameMap.clear();
@@ -419,11 +603,11 @@ void DiagramData::buildDiagramDataModel(bool /*bClearOoxShapes*/)
const bool bInserted1 = getPointNameMap().insert(
std::make_pair(point.msModelId,&point)).second;
SAL_WARN_IF(!bInserted1, "oox.drawingml", "DiagramData::build(): non-unique point model id");
SAL_WARN_IF(!bInserted1, "oox.drawingml", "DiagramData_svx::build(): non-unique point model id");
if( !point.msPresentationLayoutName.isEmpty() )
{
DiagramData::PointsNameMap::value_type::second_type& rVec=
DiagramData_svx::PointsNameMap::value_type::second_type& rVec=
getPointsPresNameMap()[point.msPresentationLayoutName];
rVec.push_back(&point);
}
@@ -484,17 +668,17 @@ void DiagramData::buildDiagramDataModel(bool /*bClearOoxShapes*/)
const bool bInserted1 = maConnectionNameMap.insert(
std::make_pair(connection.msModelId,&connection)).second;
SAL_WARN_IF(!bInserted1, "oox.drawingml", "DiagramData::build(): non-unique connection model id");
SAL_WARN_IF(!bInserted1, "oox.drawingml", "DiagramData_svx::build(): non-unique connection model id");
if( connection.mnXMLType == TypeConstant::XML_presOf )
{
DiagramData::StringMap::value_type::second_type& rVec = getPresOfNameMap()[connection.msDestId];
DiagramData_svx::StringMap::value_type::second_type& rVec = getPresOfNameMap()[connection.msDestId];
rVec[connection.mnDestOrder] = { connection.msSourceId, sal_Int32(0) };
}
}
// assign outline levels
DiagramData::StringMap& rStringMap = getPresOfNameMap();
DiagramData_svx::StringMap& rStringMap = getPresOfNameMap();
for (auto & elemPresOf : rStringMap)
{
for (auto & elem : elemPresOf.second)
@@ -508,7 +692,7 @@ void DiagramData::buildDiagramDataModel(bool /*bClearOoxShapes*/)
#endif
}
DomMapFlags DiagramData::TextInformationChange(const OUString& rDiagramDataModelID, Outliner& rOutl)
DomMapFlags DiagramData_svx::TextInformationChange(const OUString& rDiagramDataModelID, Outliner& rOutl)
{
DomMapFlags aRetval;
@@ -556,7 +740,8 @@ DomMapFlags DiagramData::TextInformationChange(const OUString& rDiagramDataModel
// prepare retval, OOXData is changed
aRetval.push_back(DomMapFlag::OOXData);
aRetval.push_back(DomMapFlag::OOXDataRels);
// aRetval.push_back(DomMapFlag::OOXDrawing);
// aRetval.push_back(DomMapFlag::OOXDataRels);
return aRetval;
}
+1 -1
View File
@@ -44,7 +44,7 @@
#include <svx/svdoashp.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
#include <svx/diagram/datamodel.hxx>
#include <svx/diagram/datamodel_svx.hxx>
#include <svx/diagram/IDiagramHelper.hxx>
#include <tools/debug.hxx>