[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Kivio Dia Stencil Import Filter
From: Nikolas Zimmermann <wildfox () kde ! org>
Date: 2001-05-20 18:48:03
[Download RAW message or body]
Hi there,
i hacked this "filter" today and it works nice :)
it supports:
Importing of Dia Shapes with complete support of
svg:line
svg:rect
svg:circle
svg:ellipse
svg:polyline
svg:polygon
TODO:
svg:rect with rounded rects
svg:g groups (needed?)
paths
Bugs (i need someone of the Kivio team to answer them):
1. Dia shapes don't containg a valid "Dimensions" field as needed
for Kivio, there is one <svg:svg width=".." height="...">
but it's not parsed of Dia, and just there to match the svg specs
stupid but true
so i need to calculate the width and height, which is working ok
problem:
- The Stencils are _very_ small in kivio (you can just see the green point)
then when you make them bigger they appear ok
- If you make them bigger you will see that the green mouse move rect
goes out of the shape ie:
[] []
.....................
.....................
.....................
[] []
.....................
.....................
where ...... is the shape, and [] is the green mouse move thinggy
seems my calcs are wrong somewhere, Dave?
Questions?
If we find that mouse issue, i'd say it's k to commit, comments?
Bye
Bye
Niko
--
Nikolas Zimmermann
wildfox@kde.org
["kivio.patch" (text/plain)]
Index: kiviosdk/Makefile.am
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/Makefile.am,v
retrieving revision 1.9
diff -u -p -b -r1.9 Makefile.am
--- kiviosdk/Makefile.am 2001/03/11 11:33:30 1.9
+++ kiviosdk/Makefile.am 2001/05/20 18:40:41
@@ -22,6 +22,7 @@ libkiviosdk_la_SOURCES = \
kivio_shape_data.cpp\
kivio_sml_stencil.cpp\
kivio_sml_stencil_spawner.cpp\
+ kivio_dia_stencil_spawner.cpp\
kivio_stencil.cpp\
kivio_stencil_spawner.cpp\
kivio_stencil_spawner_info.cpp\
Index: kiviosdk/kivio_sml_stencil.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_sml_stencil.cpp,v
retrieving revision 1.10
diff -u -p -b -r1.10 kivio_sml_stencil.cpp
--- kiviosdk/kivio_sml_stencil.cpp 2001/05/02 16:13:14 1.10
+++ kiviosdk/kivio_sml_stencil.cpp 2001/05/20 18:40:41
@@ -28,6 +28,7 @@
#include "kivio_shape.h"
#include "kivio_shape_data.h"
#include "kivio_sml_stencil.h"
+#include "kivio_dia_stencil_spawner.h"
#include "kivio_sml_stencil_spawner.h"
#include "kivio_stencil_spawner.h"
#include "kivio_stencil_spawner_info.h"
@@ -1521,7 +1522,14 @@ void KivioSMLStencil::updateGeometry()
defWidth = m_pSpawner->defWidth();
defHeight = m_pSpawner->defHeight();
- QList<KivioConnectorTarget> *pOriginalTargets = ((KivioSMLStencilSpawner*)m_pSpawner)->targets();
+ QList<KivioConnectorTarget> *pOriginalTargets;
+
+ KivioSMLStencilSpawner *smlSpawner = dynamic_cast<KivioSMLStencilSpawner *>(m_pSpawner);
+ KivioDiaStencilSpawner *diaSpawner = dynamic_cast<KivioDiaStencilSpawner *>(m_pSpawner);
+ if(smlSpawner != 0)
+ pOriginalTargets = smlSpawner->targets();
+ else if(diaSpawner != 0)
+ pOriginalTargets = diaSpawner->targets();
pTarget = m_pConnectorTargets->first();
pOriginal = pOriginalTargets->first();
Index: kiviosdk/kivio_sml_stencil_spawner.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.cpp,v
retrieving revision 1.8
diff -u -p -b -r1.8 kivio_sml_stencil_spawner.cpp
--- kiviosdk/kivio_sml_stencil_spawner.cpp 2001/03/18 20:28:16 1.8
+++ kiviosdk/kivio_sml_stencil_spawner.cpp 2001/05/20 18:40:41
@@ -76,7 +76,6 @@ QDomElement KivioSMLStencilSpawner::save
bool KivioSMLStencilSpawner::load( const QString &file )
{
- KivioConnectorTarget *pTarget;
QDomDocument d("test");
m_filename = QString(file);
@@ -87,9 +86,24 @@ bool KivioSMLStencilSpawner::load( const
kdDebug() << "KivioSMLStencilSpawner::load() - Error opening stencil: " << file << endl;
return false;
}
-
d.setContent(&f);
+ if(loadXML(file, d))
+ {
+ f.close();
+ return true;
+ }
+ else
+ {
+ f.close();
+ return false;
+ }
+}
+
+bool KivioSMLStencilSpawner::loadXML( const QString &file, QDomDocument &d )
+{
+ KivioConnectorTarget *pTarget;
+
QDomElement root = d.documentElement();
QDomElement e;
QDomNode node = root.firstChild();
@@ -137,8 +151,6 @@ bool KivioSMLStencilSpawner::load( const
m_icon.load( xpmFile );
- f.close();
-
return true;
}
Index: kiviosdk/kivio_sml_stencil_spawner.h
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_sml_stencil_spawner.h,v
retrieving revision 1.3
diff -u -p -b -r1.3 kivio_sml_stencil_spawner.h
--- kiviosdk/kivio_sml_stencil_spawner.h 2001/03/18 20:28:16 1.3
+++ kiviosdk/kivio_sml_stencil_spawner.h 2001/05/20 18:40:42
@@ -51,6 +51,7 @@ public:
virtual ~KivioSMLStencilSpawner();
virtual bool load( const QString & );
+ virtual bool loadXML( const QString &, QDomDocument & );
virtual QDomElement saveXML( QDomDocument & );
Index: kiviosdk/kivio_stencil_spawner.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.cpp,v
retrieving revision 1.4
diff -u -p -b -r1.4 kivio_stencil_spawner.cpp
--- kiviosdk/kivio_stencil_spawner.cpp 2001/03/18 20:28:16 1.4
+++ kiviosdk/kivio_stencil_spawner.cpp 2001/05/20 18:40:42
@@ -49,6 +49,10 @@ bool KivioStencilSpawner::load( const QS
return false;
}
+bool KivioStencilSpawner::loadXML( const QString &, QDomDocument & )
+{
+ return false;
+}
KivioStencil *KivioStencilSpawner::newStencil()
Index: kiviosdk/kivio_stencil_spawner.h
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_stencil_spawner.h,v
retrieving revision 1.2
diff -u -p -b -r1.2 kivio_stencil_spawner.h
--- kiviosdk/kivio_stencil_spawner.h 2001/03/18 20:28:16 1.2
+++ kiviosdk/kivio_stencil_spawner.h 2001/05/20 18:40:42
@@ -48,6 +48,7 @@ public:
virtual ~KivioStencilSpawner();
virtual bool load( const QString & );
+ virtual bool loadXML( const QString &, QDomDocument & );
virtual QDomElement saveXML( QDomDocument & );
virtual KivioStencil *newStencil();
Index: kiviosdk/kivio_stencil_spawner_set.cpp
===================================================================
RCS file: /home/kde/koffice/kivio/kiviopart/kiviosdk/kivio_stencil_spawner_set.cpp,v
retrieving revision 1.8
diff -u -p -b -r1.8 kivio_stencil_spawner_set.cpp
--- kiviosdk/kivio_stencil_spawner_set.cpp 2001/03/19 00:35:50 1.8
+++ kiviosdk/kivio_stencil_spawner_set.cpp 2001/05/20 18:40:42
@@ -19,6 +19,7 @@
#include "kivio_common.h"
#include "kivio_plugin_stencil_spawner.h"
#include "kivio_sml_stencil_spawner.h"
+#include "kivio_dia_stencil_spawner.h"
#include "kivio_py_stencil_spawner.h"
#include "kivio_stencil_spawner.h"
#include "kivio_stencil_spawner_set.h"
@@ -104,7 +105,7 @@ bool KivioStencilSpawnerSet::loadDir( co
m_name = readTitle( dirName );
m_id = readId( dirName );
- d.setNameFilter("*.sml *.ksp *.spy");
+ d.setNameFilter("*.sml *.ksp *.spy *.shape");
for( int i=0; i<(int)d.count(); i++ )
{
@@ -135,6 +136,10 @@ KivioStencilSpawner* KivioStencilSpawner
else if( fileName.contains( ".spy", false ) )
{
pSpawner = new KivioPyStencilSpawner(this);
+ }
+ else if( fileName.contains( ".shape", false ) )
+ {
+ pSpawner = new KivioDiaStencilSpawner(this);
}
else
{
["kivio_dia_stencil_spawner.h" (text/x-c++)]
/*
* Kivio - Visual Modelling and Flowcharting
* Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef KIVIO_DIA_STENCIL_SPAWNER_H
#define KIVIO_DIA_STENCIL_SPAWNER_H
#include <qdom.h>
#include <qlist.h>
#include <qstring.h>
#include "kivio_connector_target.h"
#define protected public
#include "kivio_stencil_spawner.h"
#undef protected
#include "kivio_sml_stencil_spawner.h"
class KivioDiaStencilSpawner : public KivioStencilSpawner
{
public:
KivioDiaStencilSpawner(KivioStencilSpawnerSet *);
virtual ~KivioDiaStencilSpawner();
virtual bool load(const QString &file);
virtual bool loadXML(const QString &file, QDomDocument &d);
virtual QDomElement saveXML(QDomDocument &d);
virtual QString &filename() { return m_filename; }
virtual KivioStencil *newStencil();
QList<KivioConnectorTarget> *targets() { return m_smlStencilSpawner->targets(); }
protected:
void calculateDimensions(float x, float y);
KivioSMLStencilSpawner *m_smlStencilSpawner;
QString m_filename;
float m_lowestx;
float m_lowesty;
float m_highestx;
float m_highesty;
};
#endif
["kivio_dia_stencil_spawner.cpp" (text/x-c)]
/*
* Kivio - Visual Modelling and Flowcharting
* Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qdom.h>
#include <qfile.h>
#include <qstringlist.h>
#include <kdebug.h>
#include <math.h>
#include "kivio_stencil.h"
#include "kivio_dia_stencil_spawner.h"
KivioDiaStencilSpawner::KivioDiaStencilSpawner(KivioStencilSpawnerSet *p) : \
KivioStencilSpawner(p) {
m_smlStencilSpawner = new KivioSMLStencilSpawner(p);
m_lowestx = 0;
m_lowesty = 0;
m_highestx = 0;
m_highesty = 0;
}
KivioDiaStencilSpawner::~KivioDiaStencilSpawner()
{
}
QDomElement KivioDiaStencilSpawner::saveXML(QDomDocument &d)
{
return m_smlStencilSpawner->saveXML(d);
}
void KivioDiaStencilSpawner::calculateDimensions(float x, float y)
{
if(x < 0)
{
if(x < m_lowestx)
m_lowestx = x;
}
else if(x > 0)
{
if(x > m_highestx)
m_highestx = x;
}
if(y < 0)
{
if(y < m_lowesty)
m_lowesty = y;
}
else if(y > 0)
{
if(y > m_highesty)
m_highesty = y;
}
}
bool KivioDiaStencilSpawner::load(const QString &file)
{
QDomDocument dia("test");
QDomDocument kivio("XML");
m_filename = file;
QFile f(file);
if(f.open(IO_ReadOnly) == false)
{
kdDebug() << "KivioDiaStencilSpawner::load() - Error opening stencil: " << file << \
endl; return false;
}
dia.setContent(&f);
QDomNode diaMain = dia.firstChild().nextSibling();
// Set "creator" attribute
QDomElement firstElement = kivio.createElement("KivioShapeStencil");
firstElement.setAttribute("creator", "kiviodiafilter");
kivio.appendChild(firstElement);
// Add KivioSMLStencilSpawnerInfo
QDomElement spawnerInfoElement = \
kivio.createElement("KivioSMLStencilSpawnerInfo"); QDomElement authorInfoElement = \
kivio.createElement("Author"); authorInfoElement.setAttribute("data", "n/a");
QDomElement titleInfoElement = kivio.createElement("Title");
titleInfoElement.setAttribute("data", \
diaMain.namedItem("name").toElement().text()); QDomElement idInfoElement = \
kivio.createElement("Id"); idInfoElement.setAttribute("data", \
diaMain.namedItem("name").toElement().text()); QDomElement descriptionInfoElement = \
kivio.createElement("Description"); descriptionInfoElement.setAttribute("data", \
diaMain.namedItem("description").toElement().text()); QDomElement \
versionInfoElement = kivio.createElement("Version"); \
versionInfoElement.setAttribute("data", "1.0"); QDomElement webInfoElement = \
kivio.createElement("Web"); webInfoElement.setAttribute("data", "http://");
QDomElement emailInfoElement = kivio.createElement("Email");
emailInfoElement.setAttribute("data", "n/a");
QDomElement copyrightInfoElement = kivio.createElement("Copyright");
copyrightInfoElement.setAttribute("data", "n/a");
QDomElement autoUpdateInfoElement = kivio.createElement("AutoUpdate");
autoUpdateInfoElement.setAttribute("data", "off");
spawnerInfoElement.appendChild(authorInfoElement);
spawnerInfoElement.appendChild(titleInfoElement);
spawnerInfoElement.appendChild(idInfoElement);
spawnerInfoElement.appendChild(descriptionInfoElement);
spawnerInfoElement.appendChild(versionInfoElement);
spawnerInfoElement.appendChild(webInfoElement);
spawnerInfoElement.appendChild(emailInfoElement);
spawnerInfoElement.appendChild(copyrightInfoElement);
spawnerInfoElement.appendChild(autoUpdateInfoElement);
kivio.documentElement().appendChild(spawnerInfoElement);
// Add Dimensions
QDomElement dimensionsElement = kivio.createElement("Dimensions");
kivio.documentElement().appendChild(dimensionsElement);
// Add KivioConnectorTarget's
QDomElement connectionsElement = diaMain.namedItem("connections").toElement();
QDomNode connectionsNode = connectionsElement.firstChild();
while(!connectionsNode.isNull())
{
QDomElement connectionChild = connectionsNode.toElement();
if(!connectionChild.isNull())
{
if(connectionChild.tagName() == "point")
{
if(connectionChild.hasAttribute("x") && connectionChild.hasAttribute("y"))
{
QDomElement kivioConnectorTarget = kivio.createElement("KivioConnectorTarget");
kivioConnectorTarget.setAttribute("x", connectionChild.attribute("x"));
kivioConnectorTarget.setAttribute("y", connectionChild.attribute("y"));
kivio.documentElement().appendChild(kivioConnectorTarget);
}
}
}
connectionsNode = connectionsNode.nextSibling();
}
// Add KivioShape's
QDomElement svgElement = diaMain.namedItem("svg:svg").toElement();
QDomNode svgNode = svgElement.firstChild();
int runs = 0;
while(!svgNode.isNull())
{
QDomElement svgChild = svgNode.toElement();
if(!svgChild.isNull())
{
if(svgChild.tagName() == "svg:rect")
{
runs++;
// TODO: rx and ry -> rounded rects
if(svgChild.hasAttribute("x") && svgChild.hasAttribute("y") && \
svgChild.hasAttribute("width") && svgChild.hasAttribute("height")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Rectangle");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs)); kivioShape.setAttribute("x", svgChild.attribute("x"));
kivioShape.setAttribute("y", svgChild.attribute("y"));
kivioShape.setAttribute("w", svgChild.attribute("width"));
kivioShape.setAttribute("h", svgChild.attribute("height"));
calculateDimensions(svgChild.attribute("x").toFloat(), \
svgChild.attribute("y").toFloat()); kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:circle")
{
runs++;
if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && \
svgChild.hasAttribute("r")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Ellipse");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs)); kivioShape.setAttribute("x", QString::number(0));
kivioShape.setAttribute("y", QString::number(0));
kivioShape.setAttribute("w", QString::number(svgChild.attribute("cx").toInt() + \
svgChild.attribute("r").toInt()));
kivioShape.setAttribute("h", QString::number(svgChild.attribute("cy").toInt() + \
svgChild.attribute("r").toInt()));
calculateDimensions(svgChild.attribute("cx").toFloat() + \
svgChild.attribute("r").toFloat(), svgChild.attribute("cy").toFloat() + \
svgChild.attribute("r").toFloat()); \
kivio.documentElement().appendChild(kivioShape); }
}
else if(svgChild.tagName() == "svg:ellipse")
{
runs++;
if(svgChild.hasAttribute("cx") && svgChild.hasAttribute("cy") && \
svgChild.hasAttribute("rx") && svgChild.hasAttribute("ry")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Ellipse");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs)); kivioShape.setAttribute("x", svgChild.attribute("cx"));
kivioShape.setAttribute("y", svgChild.attribute("cy"));
kivioShape.setAttribute("w", svgChild.attribute("rx"));
kivioShape.setAttribute("h", svgChild.attribute("ry"));
calculateDimensions(svgChild.attribute("cx").toFloat() + \
svgChild.attribute("rx").toFloat(), svgChild.attribute("cy").toFloat() + \
svgChild.attribute("ry").toFloat()); \
kivio.documentElement().appendChild(kivioShape); }
}
else if(svgChild.tagName() == "svg:line")
{
runs++;
if(svgChild.hasAttribute("x1") && svgChild.hasAttribute("y1") && \
svgChild.hasAttribute("x2") && svgChild.hasAttribute("y2")) {
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "LineArray");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
QDomElement lineArrayElement = kivio.createElement("Line");
lineArrayElement.setAttribute("x1", svgChild.attribute("x1"));
lineArrayElement.setAttribute("y1", svgChild.attribute("y1"));
lineArrayElement.setAttribute("x2", svgChild.attribute("x2"));
lineArrayElement.setAttribute("y2", svgChild.attribute("y2"));
calculateDimensions(svgChild.attribute("x1").toFloat(), \
svgChild.attribute("y1").toFloat());
calculateDimensions(svgChild.attribute("x2").toFloat(), \
svgChild.attribute("y2").toFloat()); kivioShape.appendChild(lineArrayElement);
kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:polyline")
{
runs++;
if(svgChild.hasAttribute("points"))
{
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Polyline");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
QStringList points = QStringList::split(" ", svgChild.attribute("points"));
for(QStringList::Iterator it = points.begin(); it != points.end(); ++it)
{
QString x, y;
QStringList parsed = QStringList::split(",", (*it));
QStringList::Iterator itp = parsed.begin();
x = (*itp);
++itp;
y = (*itp);
calculateDimensions(x.toFloat(), y.toFloat());
QDomElement kivioPointElement = kivio.createElement("KivioPoint");
kivioPointElement.setAttribute("x", x);
kivioPointElement.setAttribute("y", y);
kivioShape.appendChild(kivioPointElement);
}
kivio.documentElement().appendChild(kivioShape);
}
}
else if(svgChild.tagName() == "svg:polygon")
{
runs++;
if(svgChild.hasAttribute("points"))
{
QDomElement kivioShape = kivio.createElement("KivioShape");
kivioShape.setAttribute("type", "Polygon");
kivioShape.setAttribute("name", QString::fromLatin1("Element") + \
QString::number(runs));
QStringList points = QStringList::split(" ", svgChild.attribute("points"));
for(QStringList::Iterator it = points.begin(); it != points.end(); ++it)
{
QString x, y;
QStringList parsed = QStringList::split(",", (*it));
QStringList::Iterator itp = parsed.begin();
x = (*itp);
++itp;
y = (*itp);
calculateDimensions(x.toFloat(), y.toFloat());
QDomElement kivioPointElement = kivio.createElement("KivioPoint");
kivioPointElement.setAttribute("x", x);
kivioPointElement.setAttribute("y", y);
kivioShape.appendChild(kivioPointElement);
}
kivio.documentElement().appendChild(kivioShape);
}
}
}
svgNode = svgNode.nextSibling();
}
// Apply width and height
dimensionsElement.setAttribute("w", QString::number(fabs(m_highestx - \
m_lowestx))); dimensionsElement.setAttribute("h", QString::number(fabs(m_highesty - \
m_lowesty)));
return loadXML(file, kivio);
}
bool KivioDiaStencilSpawner::loadXML(const QString &file, QDomDocument &d)
{
bool ret = m_smlStencilSpawner->loadXML(file, d);
m_icon = m_smlStencilSpawner->m_icon;
m_pSet = m_smlStencilSpawner->m_pSet;
m_pInfo = m_smlStencilSpawner->m_pInfo;
m_defWidth = m_smlStencilSpawner->m_defWidth;
m_defHeight = m_smlStencilSpawner->m_defHeight;
return ret;
}
KivioStencil *KivioDiaStencilSpawner::newStencil()
{
KivioStencil *newStencil = m_smlStencilSpawner->newStencil();
newStencil->setSpawner(this);
return newStencil;
}
_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic