31 #define KIG_CABRI_FILTER_PARSE_ERROR \
33 QString locs = i18n( "An error was encountered at line %1 in file %2.", \
34 __LINE__, __FILE__ ); \
35 m_filter->publicParseError( file, locs ); \
41 typedef std::map<QString, QColor>::iterator
cmit;
49 if ( type ==
"Line" || type ==
"Ray" || type ==
"Seg" )
51 if ( type ==
"Pt" || type ==
"Pt/" || type ==
"Locus" )
56 return QColor( 254, 0, 255 );
60 return QColor( 0, 0, 128 );
61 if ( type ==
"Text" || type ==
"Angle" )
74 QRegExp ids(
"\\d+" );
76 while ( ( pos = ids.indexIn( tmp ) ) > -1 )
78 vec.push_back( ids.cap( 0 ).toInt( &ok ) );
79 if ( !ok )
return false;
80 tmp.remove( pos, ids.matchedLength() );
91 QString ret = file.readLine( 10000L );
92 if ( !ret.isEmpty() && ret[ret.length() - 1] ==
'\n' )
93 ret.truncate( ret.length() - 1 );
94 if ( !ret.isEmpty() && ret[ret.length() - 1] ==
'\r' )
95 ret.truncate( ret.length() - 1 );
99 QString
readText( QFile& f,
const QString& s,
const QString& sep )
102 if ( !line.startsWith(
'\"' ) || f.atEnd() )
108 while ( tmp.at( tmp.length() - 1 ) !=
'"' )
113 QString ret = text.mid( 1, text.length() - 2 );
115 kDebug() <<
"+++++++++ text: \"" << ret <<
"\"";
123 : id( 0 ), thick( 1 ), lineSegLength( 0 ), lineSegSplit( 0 ), visible( true ),
124 intersectionId( 0 ), ticks( 0 ), side( 0 ), textRect(
Rect::invalidRect() ),
130 :
CabriObject(), specialAppearanceSwitch( 0 ), fixed( false )
151 static bool colors_initialized =
false;
152 if ( !colors_initialized )
154 colors_initialized =
true;
164 colormap[
"Br" ] = QColor( 165, 42, 42 );
165 colormap[
"dBr" ] = QColor( 128, 128, 0 );
178 if ( it !=
colormap.end() )
return (*it).second;
180 kDebug() <<
"unknown color: " << s;
196 QString file = f.fileName();
199 QRegExp first(
"^Window center x: (.+) y: (.+) Window size x: (.+) y: (.+)$" );
200 if ( !first.exactMatch( line ) )
212 QString file = f.fileName();
218 QRegExp namelinere(
"^\"([^\"]+)\", NP: ([\\d-]+), ([\\d-]+), NS: (\\d+), (\\d+)$" );
219 if ( namelinere.exactMatch( line1 ) )
221 tmp = namelinere.cap( 1 );
227 QRegExp firstlinere(
"^([^:]+): ([^,]+), ([^,]+), CN:([^,]*), VN:(.*)$" );
228 if ( ! firstlinere.exactMatch( line1 ) )
231 tmp = firstlinere.cap( 1 );
232 myobj->
id = tmp.toUInt( &ok );
235 tmp = firstlinere.cap( 2 );
236 myobj->
type = tmp.toLatin1();
238 tmp = firstlinere.cap( 3 );
245 tmp = firstlinere.cap( 4 );
246 uint numberOfParents = tmp.toUInt( &ok );
249 tmp = firstlinere.cap( 5 );
253 QRegExp secondlinere(
"^([^,]+), ([^,]+), ([^,]+), DS:([^ ]+) ([^,]+), GT:([^,]+), ([^,]+), (.*)$" );
254 QRegExp secondlinere2(
"^([^,]+), ([^,]+), NbD:([^,]+), ([^,]+), ([^,]+), GT:([^,]+), ([^,]+), (.*)$" );
255 if ( secondlinere.exactMatch( line2 ) )
257 tmp = secondlinere.cap( 1 );
260 tmp = secondlinere.cap( 2 );
263 tmp = secondlinere.cap( 3 );
264 myobj->
thick = tmp ==
"t" ? 1 : tmp ==
"tT" ? 2 : 3;
266 tmp = secondlinere.cap( 4 );
270 tmp = secondlinere.cap( 5 );
274 tmp = secondlinere.cap( 6 );
278 tmp = secondlinere.cap( 7 );
281 tmp = secondlinere.cap( 8 );
282 myobj->
fixed = tmp ==
"St";
284 else if ( secondlinere2.exactMatch( line2 ) )
286 tmp = secondlinere2.cap( 1 );
289 tmp = secondlinere2.cap( 2 );
295 tmp = secondlinere2.cap( 5 );
299 tmp = secondlinere2.cap( 6 );
303 tmp = secondlinere2.cap( 7 );
306 tmp = secondlinere2.cap( 8 );
307 myobj->
fixed = tmp ==
"St";
314 QRegExp thirdlinere(
"^(Const: ([^,]*),? ?)?(Val: ([^,]*)(,(.*))?)?$" );
315 if ( ! thirdlinere.exactMatch( line3 ) )
318 tmp = thirdlinere.cap( 2 );
319 const QStringList parentsids = tmp.split(
' ', QString::SkipEmptyParts );
320 for ( QStringList::const_iterator i = parentsids.begin();
321 i != parentsids.end(); ++i )
323 myobj->
parents.push_back( ( *i ).toInt( &ok ) );
326 if ( myobj->
parents.size() != numberOfParents )
329 tmp = thirdlinere.cap( 4 );
330 const QStringList valIds = tmp.split(
' ', QString::SkipEmptyParts );
331 for ( QStringList::const_iterator i = valIds.begin();
332 i != valIds.end(); ++i )
334 myobj->
data.push_back( ( *i ).toDouble( &ok ) );
338 QString thirdlineextra = thirdlinere.cap( 6 );
339 if ( myobj->
type ==
"Text" || myobj->
type ==
"Formula" )
341 QRegExp textMetrics(
"TP: *[\\s]*([^,]+), *[\\s]*([^,]+), *TS:[\\s]*([^,]+), *[\\s]*([^,]+)" );
342 if ( textMetrics.indexIn( thirdlineextra ) != -1 )
344 double xa = textMetrics.cap( 1 ).toDouble( &ok );
346 double ya = textMetrics.cap( 2 ).toDouble( &ok );
348 double tw = textMetrics.cap( 3 ).toDouble( &ok );
350 double th = textMetrics.cap( 4 ).toDouble( &ok );
355 if ( textline.isEmpty() )
357 if ( myobj->
type ==
"Formula" )
360 myobj->
text = textline;
371 int count = myobj->
text.count(
"\"#" );
372 int parentsnum = myobj->
parents.size();
373 for (
int i = parentsnum - count; i < parentsnum; ++i )
378 if ( !line4.isEmpty() )
380 QRegExp fontlinere(
"^p: (\\d+), ([^,]+), S: (\\d+) C: (\\d+) Fa: (\\d+)$" );
381 if ( !fontlinere.exactMatch( line4 ) )
414 if ( ( myobj->
type ==
"Pt" ) || ( myobj->
type ==
"Pt/" ) )
463 void CabriReader_v12::initColorMap()
465 static bool colors_initialized =
false;
466 if ( !colors_initialized )
468 colors_initialized =
true;
506 QString file = f.fileName();
509 QRegExp first(
"^Window center x: (.+) y: (.+) Window size x: (.+) y: (.+)$" );
510 if ( !first.exactMatch( line ) )
514 QRegExp second(
"^Resolution: (\\d+) ppc$" );
515 if ( !second.exactMatch( line2 ) )
527 QString file = f.fileName();
531 kDebug() <<
"+++++++++ line: \"" << line <<
"\"";
533 QRegExp firstlinere(
"^([^:]+): ([^,]+), (Const: [,0-9\\s]+)?(int ind:([^,]+),\\s)?(cart, )?(side:(\\d+), )?(inc\\.elmts: ([,0-9\\s]+))?(axis:(x|y), )?(on mark, )?(Val: ([^,]+))?(.*)$" );
534 if ( !firstlinere.exactMatch( line ) )
541 tmp = firstlinere.cap( 1 );
542 myobj->
id = tmp.toUInt( &ok );
546 tmp = firstlinere.cap( 2 );
547 myobj->
type = tmp.toLatin1();
550 tmp = firstlinere.cap( 3 );
555 tmp = firstlinere.cap( 15 );
556 const QStringList valIds = tmp.split(
' ', QString::SkipEmptyParts );
557 for ( QStringList::const_iterator i = valIds.begin(); i != valIds.end(); ++i )
559 myobj->
data.push_back( ( *i ).toDouble( &ok ) );
564 tmp = firstlinere.cap( 5 );
565 if ( !tmp.isEmpty() )
567 long intId = tmp.toLong( &ok, 16 );
570 kDebug() <<
"+++++++++ intId: " << intId;
578 tmp = firstlinere.cap( 8 );
579 if ( !tmp.isEmpty() )
581 myobj->
side = tmp.toInt( &ok );
586 tmp = firstlinere.cap( 10 );
592 QRegExp textMetrics(
"^TP:[\\s]*([^,]+),[\\s]*([^,]+), TS:[\\s]*([^,]+),[\\s]*([^,]+)$" );
593 bool freeText =
false;
594 while ( !line.isEmpty() )
596 if ( line.startsWith(
'\"' ) )
599 if ( myobj->
type !=
"Text" )
604 else if ( line.startsWith(
"NbD:" ) )
608 else if ( textMetrics.exactMatch( line ) )
610 double xa = textMetrics.cap( 1 ).toDouble( &ok );
612 double ya = textMetrics.cap( 2 ).toDouble( &ok );
614 double tw = textMetrics.cap( 3 ).toDouble( &ok );
616 double th = textMetrics.cap( 4 ).toDouble( &ok );
622 if ( !freeText && myobj->
type ==
"Formula" )
628 readStyles( file, line, myobj );
635 if ( !myobj->
color.isValid() )
645 if ( ( myobj->
type ==
"Pt" ) || ( myobj->
type ==
"Pt/" ) )
693 kDebug() <<
"unknown color: " << s;
697 bool CabriReader_v12::readStyles(
const QString& file,
const QString& line,
CabriObject_v12* myobj )
700 kDebug() <<
">>>>>>>>> style line: \"" << line <<
"\"";
702 QStringList styles = line.split(
", ", QString::SkipEmptyParts );
704 for ( QStringList::iterator it = styles.begin(); it != styles.end(); ++it )
706 if ( (*it) ==
"invisible" )
710 else if ( (*it).startsWith(
"DS:" ) )
712 QRegExp ticks(
"DS:(\\d+)\\s(\\d+)" );
713 if ( ticks.exactMatch( (*it) ) )
722 else if ( (*it).startsWith(
"color:" ) )
724 QString color = (*it).remove( 0, 6 );
727 else if ( (*it).startsWith(
"fill color:" ) )
729 QString color = (*it).remove( 0, 11 );
733 else if ( (*it) ==
"thicker" )
737 else if ( (*it) ==
"thick" )
742 else if ( (*it) ==
"1x1" )
746 else if ( (*it) ==
"CIRCLE" )
750 else if ( (*it) ==
"TIMES" )
754 else if ( (*it) ==
"PLUS" )
759 else if ( (*it) ==
"deg" )
764 else if ( (*it).startsWith(
"marks nb:" ) )
766 QString strticks = (*it).remove( 0, 9 );
767 myobj->
ticks = strticks.toInt( &ok );
773 kDebug() <<
">>>>>>>>> UNKNOWN STYLE STRING: \"" << *it <<
"\"";
virtual void decodeStyle(CabriObject *obj, Qt::PenStyle &ps, int &pointType)
virtual ~CabriReader_v10()
static void initColorMap()
This file is part of Kig, a KDE program for Interactive Geometry...
CabriNS::CabriGonio gonio
virtual bool readWindowMetrics(QFile &f)
virtual bool readWindowMetrics(QFile &f)
virtual void decodeStyle(CabriObject *obj, Qt::PenStyle &ps, int &pointType)
CabriReader_v10(const KigFilterCabri *filter)
std::vector< int > parents
QString readLine(QFile &file)
Read a line from a Cabri file, stripping the \n and \r characters.
virtual CabriObject * readObject(QFile &f)
static QColor translateColor(const QString &s)
Translate a color from a 1 to 3 character sequence.
CabriReader_v12(const KigFilterCabri *filter)
static std::map< QString, QColor > colormap
static QColor defaultColorForObject(const QByteArray &type)
Gives the default color for an object, in case of an object come with no color specified; it's exactl...
This is an import filter for the output of the commercial program Cabri ("CAhier de BRouillon Interac...
virtual CabriObject * readObject(QFile &f)
CabriReader(const KigFilterCabri *filter)
QString readText(QFile &f, const QString &s, const QString &sep)
Base reader for a Cabri figure.
static QColor translateColor(const QString &s)
virtual ~CabriReader_v12()
std::vector< double > data
static bool extractValuesFromString(const QString &str, std::vector< int > &vec)
#define KIG_CABRI_FILTER_PARSE_ERROR
static std::map< QString, QColor > colormap_v12
Base class representing a Cabri object.
std::map< QString, QColor >::iterator cmit
int specialAppearanceSwitch