00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "cabri-utils.h"
00021
00022 #include "cabri-filter.h"
00023
00024 #include <qfile.h>
00025 #include <qregexp.h>
00026 #include <qstring.h>
00027
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030
00031 #define KIG_CABRI_FILTER_PARSE_ERROR \
00032 { \
00033 QString locs = i18n( "An error was encountered at line %1 in file %2.", \
00034 __LINE__, __FILE__ ); \
00035 m_filter->publicParseError( file, locs ); \
00036 return 0; \
00037 }
00038
00039 static std::map<QString, QColor> colormap;
00040 static std::map<QString, QColor> colormap_v12;
00041 typedef std::map<QString, QColor>::iterator cmit;
00042
00047 static QColor defaultColorForObject( const QByteArray& type )
00048 {
00049 if ( type == "Line" || type == "Ray" || type == "Seg" )
00050 return Qt::green;
00051 if ( type == "Pt" || type == "Pt/" || type == "Locus" )
00052 return Qt::red;
00053 if ( type == "Cir" )
00054 return Qt::blue;
00055 if ( type == "Pol" )
00056 return QColor( 254, 0, 255 );
00057 if ( type == "Arc" )
00058 return Qt::cyan;
00059 if ( type == "Vec" )
00060 return QColor( 0, 0, 128 );
00061 if ( type == "Text" || type == "Angle" )
00062 return Qt::black;
00063
00064 return Qt::blue;
00065 }
00066
00067 static bool extractValuesFromString( const QString& str, std::vector<int>& vec )
00068 {
00069 if ( !str.isEmpty() )
00070 {
00071 QString tmp = str;
00072 bool ok = true;
00073
00074 QRegExp ids( "\\d+" );
00075 int pos = -1;
00076 while ( ( pos = ids.indexIn( tmp ) ) > -1 )
00077 {
00078 vec.push_back( ids.cap( 0 ).toInt( &ok ) );
00079 if ( !ok ) return false;
00080 tmp.remove( pos, ids.matchedLength() );
00081 }
00082 }
00083 return true;
00084 }
00085
00086
00087 namespace CabriNS
00088 {
00089 QString readLine( QFile& file )
00090 {
00091 QString ret = file.readLine( 10000L );
00092 if ( !ret.isEmpty() && ret[ret.length() - 1] == '\n' )
00093 ret.truncate( ret.length() - 1 );
00094 if ( !ret.isEmpty() && ret[ret.length() - 1] == '\r' )
00095 ret.truncate( ret.length() - 1 );
00096 return ret;
00097 }
00098
00099 QString readText( QFile& f, const QString& s, const QString& sep )
00100 {
00101 QString line = s;
00102 if ( !line.startsWith( '\"' ) || f.atEnd() )
00103
00104 return QString();
00105
00106 QString tmp = s;
00107 QString text = tmp;
00108 while ( tmp.at( tmp.length() - 1 ) != '"' )
00109 {
00110 tmp = readLine( f );
00111 text += sep + tmp;
00112 }
00113 QString ret = text.mid( 1, text.length() - 2 );
00114
00115 kDebug() << "+++++++++ text: \"" << ret << "\"";
00116
00117 return ret;
00118 }
00119
00120 }
00121
00122 CabriObject::CabriObject()
00123 : id( 0 ), thick( 1 ), lineSegLength( 0 ), lineSegSplit( 0 ), visible( true ),
00124 intersectionId( 0 ), ticks( 0 ), side( 0 ), textRect( Rect::invalidRect() ),
00125 gonio( CabriNS::CG_Deg )
00126 {
00127 }
00128
00129 CabriObject_v10::CabriObject_v10()
00130 : CabriObject(), specialAppearanceSwitch( 0 ), fixed( false )
00131 {
00132 }
00133
00134 CabriObject_v12::CabriObject_v12()
00135 : CabriObject(), pointStyle( 1 )
00136 {
00137 }
00138
00139 CabriReader::CabriReader( const KigFilterCabri* filter )
00140 : m_filter( filter )
00141 {
00142 initColorMap();
00143 }
00144
00145 CabriReader::~CabriReader()
00146 {
00147 }
00148
00149 void CabriReader::initColorMap()
00150 {
00151 static bool colors_initialized = false;
00152 if ( !colors_initialized )
00153 {
00154 colors_initialized = true;
00155 colormap[ "R" ] = Qt::red;
00156 colormap[ "O" ] = Qt::magenta;
00157 colormap[ "Y" ] = Qt::yellow;
00158 colormap[ "P" ] = Qt::darkMagenta;
00159 colormap[ "V" ] = Qt::darkBlue;
00160 colormap[ "Bl" ] = Qt::blue;
00161 colormap[ "lBl" ] = Qt::cyan;
00162 colormap[ "G" ] = Qt::green;
00163 colormap[ "dG" ] = Qt::darkGreen;
00164 colormap[ "Br" ] = QColor( 165, 42, 42 );
00165 colormap[ "dBr" ] = QColor( 128, 128, 0 );
00166 colormap[ "lGr" ] = Qt::lightGray;
00167 colormap[ "Gr" ] = Qt::gray;
00168 colormap[ "dGr" ] = Qt::darkGray;
00169 colormap[ "B" ] = Qt::black;
00170 colormap[ "W" ] = Qt::white;
00171 }
00172 }
00173
00174 QColor CabriReader::translateColor( const QString& s )
00175 {
00176 initColorMap();
00177 cmit it = colormap.find( s );
00178 if ( it != colormap.end() ) return (*it).second;
00179
00180 kDebug() << "unknown color: " << s;
00181 return Qt::black;
00182 }
00183
00184
00185 CabriReader_v10::CabriReader_v10( const KigFilterCabri* filter )
00186 : CabriReader( filter )
00187 {
00188 }
00189
00190 CabriReader_v10::~CabriReader_v10()
00191 {
00192 }
00193
00194 bool CabriReader_v10::readWindowMetrics( QFile& f )
00195 {
00196 QString file = f.fileName();
00197
00198 QString line = CabriNS::readLine( f );
00199 QRegExp first( "^Window center x: (.+) y: (.+) Window size x: (.+) y: (.+)$" );
00200 if ( !first.exactMatch( line ) )
00201 KIG_CABRI_FILTER_PARSE_ERROR;
00202
00203 line = CabriNS::readLine( f );
00204
00205 return true;
00206 }
00207
00208 CabriObject* CabriReader_v10::readObject( QFile& f )
00209 {
00210 CabriObject_v10* myobj = new CabriObject_v10();
00211
00212 QString file = f.fileName();
00213
00214 bool ok;
00215 QString tmp;
00216
00217 QString line1 = CabriNS::readLine( f );
00218 QRegExp namelinere( "^\"([^\"]+)\", NP: ([\\d-]+), ([\\d-]+), NS: (\\d+), (\\d+)$" );
00219 if ( namelinere.exactMatch( line1 ) )
00220 {
00221 tmp = namelinere.cap( 1 );
00222 myobj->name = tmp;
00223
00224 line1 = CabriNS::readLine( f );
00225 }
00226
00227 QRegExp firstlinere( "^([^:]+): ([^,]+), ([^,]+), CN:([^,]*), VN:(.*)$" );
00228 if ( ! firstlinere.exactMatch( line1 ) )
00229 KIG_CABRI_FILTER_PARSE_ERROR;
00230
00231 tmp = firstlinere.cap( 1 );
00232 myobj->id = tmp.toUInt( &ok );
00233 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00234
00235 tmp = firstlinere.cap( 2 );
00236 myobj->type = tmp.toLatin1();
00237
00238 tmp = firstlinere.cap( 3 );
00239 myobj->specification = tmp.toInt( &ok );
00240 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00241
00242
00243
00244
00245 tmp = firstlinere.cap( 4 );
00246 uint numberOfParents = tmp.toUInt( &ok );
00247 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00248
00249 tmp = firstlinere.cap( 5 );
00250
00251
00252 QString line2 = CabriNS::readLine( f );
00253 QRegExp secondlinere( "^([^,]+), ([^,]+), ([^,]+), DS:([^ ]+) ([^,]+), GT:([^,]+), ([^,]+), (.*)$" );
00254 QRegExp secondlinere2( "^([^,]+), ([^,]+), NbD:([^,]+), ([^,]+), ([^,]+), GT:([^,]+), ([^,]+), (.*)$" );
00255 if ( secondlinere.exactMatch( line2 ) )
00256 {
00257 tmp = secondlinere.cap( 1 );
00258 myobj->color = translateColor( tmp );
00259
00260 tmp = secondlinere.cap( 2 );
00261 myobj->fillColor = translateColor( tmp );
00262
00263 tmp = secondlinere.cap( 3 );
00264 myobj->thick = tmp == "t" ? 1 : tmp == "tT" ? 2 : 3;
00265
00266 tmp = secondlinere.cap( 4 );
00267 myobj->lineSegLength = tmp.toInt( &ok );
00268 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00269
00270 tmp = secondlinere.cap( 5 );
00271 myobj->lineSegSplit = tmp.toInt( &ok );
00272 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00273
00274 tmp = secondlinere.cap( 6 );
00275 myobj->specialAppearanceSwitch = tmp.toInt( &ok );
00276 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00277
00278 tmp = secondlinere.cap( 7 );
00279 myobj->visible = tmp == "V";
00280
00281 tmp = secondlinere.cap( 8 );
00282 myobj->fixed = tmp == "St";
00283 }
00284 else if ( secondlinere2.exactMatch( line2 ) )
00285 {
00286 tmp = secondlinere2.cap( 1 );
00287 myobj->color = translateColor( tmp );
00288
00289 tmp = secondlinere2.cap( 2 );
00290 myobj->fillColor = translateColor( tmp );
00291
00292
00293
00294
00295 tmp = secondlinere2.cap( 5 );
00296 if ( tmp == "deg" )
00297 myobj->gonio = CabriNS::CG_Deg;
00298
00299 tmp = secondlinere2.cap( 6 );
00300 myobj->specialAppearanceSwitch = tmp.toInt( &ok );
00301 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00302
00303 tmp = secondlinere2.cap( 7 );
00304 myobj->visible = tmp == "V";
00305
00306 tmp = secondlinere2.cap( 8 );
00307 myobj->fixed = tmp == "St";
00308
00309 }
00310 else
00311 KIG_CABRI_FILTER_PARSE_ERROR;
00312
00313 QString line3 = CabriNS::readLine( f );
00314 QRegExp thirdlinere( "^(Const: ([^,]*),? ?)?(Val: ([^,]*)(,(.*))?)?$" );
00315 if ( ! thirdlinere.exactMatch( line3 ) )
00316 KIG_CABRI_FILTER_PARSE_ERROR;
00317
00318 tmp = thirdlinere.cap( 2 );
00319 QStringList parentsids = tmp.split( ' ', QString::SkipEmptyParts );
00320 for ( QStringList::iterator i = parentsids.begin();
00321 i != parentsids.end(); ++i )
00322 {
00323 myobj->parents.push_back( ( *i ).toInt( &ok ) );
00324 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00325 }
00326 if ( myobj->parents.size() != numberOfParents )
00327 KIG_CABRI_FILTER_PARSE_ERROR;
00328
00329 tmp = thirdlinere.cap( 4 );
00330 QStringList valIds = tmp.split( ' ', QString::SkipEmptyParts );
00331 for ( QStringList::iterator i = valIds.begin();
00332 i != valIds.end(); ++i )
00333 {
00334 myobj->data.push_back( ( *i ).toDouble( &ok ) );
00335 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00336 }
00337
00338 QString thirdlineextra = thirdlinere.cap( 6 );
00339 if ( myobj->type == "Text" || myobj->type == "Formula" )
00340 {
00341 QRegExp textMetrics( "TP: *[\\s]*([^,]+), *[\\s]*([^,]+), *TS:[\\s]*([^,]+), *[\\s]*([^,]+)" );
00342 if ( textMetrics.indexIn( thirdlineextra ) != -1 )
00343 {
00344 double xa = textMetrics.cap( 1 ).toDouble( &ok );
00345 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00346 double ya = textMetrics.cap( 2 ).toDouble( &ok );
00347 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00348 double tw = textMetrics.cap( 3 ).toDouble( &ok );
00349 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00350 double th = textMetrics.cap( 4 ).toDouble( &ok );
00351 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00352 myobj->textRect = Rect( xa, ya, tw, th );
00353 }
00354 QString textline = CabriNS::readLine( f );
00355 if ( textline.isEmpty() )
00356 KIG_CABRI_FILTER_PARSE_ERROR;
00357 if ( myobj->type == "Formula" )
00358 {
00359
00360 myobj->text = textline;
00361 }
00362 else
00363 myobj->text = CabriNS::readText( f, textline, "\n" );
00364
00365
00366
00367
00368
00369
00370
00371 int count = myobj->text.count( "\"#" );
00372 int parentsnum = myobj->parents.size();
00373 for ( int i = parentsnum - count; i < parentsnum; ++i )
00374 myobj->incs.push_back( myobj->parents[i] );
00375 }
00376
00377 QString line4 = CabriNS::readLine( f );
00378 if ( !line4.isEmpty() )
00379 {
00380 QRegExp fontlinere( "^p: (\\d+), ([^,]+), S: (\\d+) C: (\\d+) Fa: (\\d+)$" );
00381 if ( !fontlinere.exactMatch( line4 ) )
00382 KIG_CABRI_FILTER_PARSE_ERROR;
00383
00384 line4 = CabriNS::readLine( f );
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 return myobj;
00408 }
00409
00410 void CabriReader_v10::decodeStyle( CabriObject* obj, Qt::PenStyle& ps, int& pointType )
00411 {
00412 CabriObject_v10* myobj = (CabriObject_v10*)obj;
00413
00414 if ( ( myobj->type == "Pt" ) || ( myobj->type == "Pt/" ) )
00415 {
00416 switch ( myobj->specialAppearanceSwitch )
00417 {
00418 case 0:
00419 {
00420 myobj->thick -= 1;
00421 break;
00422 }
00423 case 2:
00424 {
00425 myobj->thick += 1;
00426 break;
00427 }
00428 case 3:
00429 {
00430 myobj->thick += 1;
00431 pointType = 1;
00432 break;
00433 }
00434 case 4:
00435 {
00436 myobj->thick += 2;
00437 pointType = 4;
00438 break;
00439 }
00440 }
00441 myobj->thick *= 2;
00442 }
00443 else
00444 {
00445 if ( ( myobj->lineSegLength > 1 ) && ( myobj->lineSegLength < 6 ) &&
00446 ( myobj->lineSegSplit > 1 ) && ( myobj->lineSegSplit <= 10 ) )
00447 ps = Qt::DotLine;
00448 else if ( ( myobj->lineSegLength >= 6 ) && ( myobj->lineSegSplit > 10 ) )
00449 ps = Qt::DashLine;
00450 }
00451 }
00452
00453 CabriReader_v12::CabriReader_v12( const KigFilterCabri* filter )
00454 : CabriReader( filter )
00455 {
00456 initColorMap();
00457 }
00458
00459 CabriReader_v12::~CabriReader_v12()
00460 {
00461 }
00462
00463 void CabriReader_v12::initColorMap()
00464 {
00465 static bool colors_initialized = false;
00466 if ( !colors_initialized )
00467 {
00468 colors_initialized = true;
00469 CabriReader::initColorMap();
00470 colormap_v12 = colormap;
00471 colormap_v12[ "dkg" ] = QColor( 0, 100, 0 );
00472 colormap_v12[ "old" ] = QColor( 107, 142, 35 );
00473 colormap_v12[ "olv" ] = QColor( 128, 128, 0 );
00474 colormap_v12[ "lig" ] = QColor( 50, 205, 50 );
00475 colormap_v12[ "gry" ] = QColor( 173, 255, 47 );
00476 colormap_v12[ "gor" ] = QColor( 218, 165, 32 );
00477 colormap_v12[ "msg" ] = QColor( 0, 250, 154 );
00478 colormap_v12[ "spg" ] = QColor( 0, 255, 127 );
00479 colormap_v12[ "pag" ] = QColor( 152, 251, 152 );
00480 colormap_v12[ "kki" ] = QColor( 240, 230, 140 );
00481 colormap_v12[ "O" ] = QColor( 255, 140, 0 );
00482 colormap_v12[ "Br" ] = QColor( 165, 42, 42 );
00483 colormap_v12[ "tea" ] = QColor( 0, 128, 128 );
00484 colormap_v12[ "pat" ] = QColor( 175, 238, 238 );
00485 colormap_v12[ "ltp" ] = QColor( 255, 182, 193 );
00486 colormap_v12[ "dBr" ] = QColor( 128, 0, 0 );
00487 colormap_v12[ "lsg" ] = QColor( 32, 178, 170 );
00488 colormap_v12[ "dob" ] = QColor( 30, 144, 255 );
00489 colormap_v12[ "skb" ] = QColor( 135, 206, 235 );
00490 colormap_v12[ "plm" ] = QColor( 221, 160, 221 );
00491 colormap_v12[ "dep" ] = QColor( 255, 20, 147 );
00492 colormap_v12[ "crs" ] = QColor( 220, 20, 60 );
00493 colormap_v12[ "rob" ] = QColor( 65, 105, 225 );
00494 colormap_v12[ "blv" ] = QColor( 138, 43, 226 );
00495 colormap_v12[ "ma" ] = QColor( 254, 0, 255 );
00496 colormap_v12[ "mvr" ] = QColor( 199, 21, 133 );
00497 colormap_v12[ "ind" ] = QColor( 75, 0, 130 );
00498 colormap_v12[ "meo" ] = QColor( 186, 85, 211 );
00499 colormap_v12[ "Gr" ] = QColor( 128, 128, 128 );
00500 colormap_v12[ "dGr" ] = QColor( 64, 64, 64 );
00501 }
00502 }
00503
00504 bool CabriReader_v12::readWindowMetrics( QFile& f )
00505 {
00506 QString file = f.fileName();
00507
00508 QString line = CabriNS::readLine( f );
00509 QRegExp first( "^Window center x: (.+) y: (.+) Window size x: (.+) y: (.+)$" );
00510 if ( !first.exactMatch( line ) )
00511 KIG_CABRI_FILTER_PARSE_ERROR;
00512
00513 QString line2 = CabriNS::readLine( f );
00514 QRegExp second( "^Resolution: (\\d+) ppc$" );
00515 if ( !second.exactMatch( line2 ) )
00516 KIG_CABRI_FILTER_PARSE_ERROR;
00517
00518 line = CabriNS::readLine( f );
00519
00520 return true;
00521 }
00522
00523 CabriObject* CabriReader_v12::readObject( QFile& f )
00524 {
00525 CabriObject_v12* myobj = new CabriObject_v12();
00526
00527 QString file = f.fileName();
00528 QString line = CabriNS::readLine( f );
00529
00530 #ifdef CABRI_DEBUG
00531 kDebug() << "+++++++++ line: \"" << line << "\"";
00532 #endif
00533 QRegExp firstlinere( "^([^:]+): ([^,]+), (Const: [,0-9\\s]+)?(int ind:([^,]+),\\s)?(cart, )?(side:(\\d+), )?(inc\\.elmts: ([,0-9\\s]+))?(axis:(x|y), )?(on mark, )?(Val: ([^,]+))?(.*)$" );
00534 if ( !firstlinere.exactMatch( line ) )
00535 KIG_CABRI_FILTER_PARSE_ERROR;
00536
00537 bool ok = true;
00538 QString tmp;
00539
00540
00541 tmp = firstlinere.cap( 1 );
00542 myobj->id = tmp.toUInt( &ok );
00543 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00544
00545
00546 tmp = firstlinere.cap( 2 );
00547 myobj->type = tmp.toLatin1();
00548
00549
00550 tmp = firstlinere.cap( 3 );
00551 if ( !extractValuesFromString( tmp, myobj->parents ) )
00552 KIG_CABRI_FILTER_PARSE_ERROR;
00553
00554
00555 tmp = firstlinere.cap( 15 );
00556 QStringList valIds = tmp.split( ' ', QString::SkipEmptyParts );
00557 for ( QStringList::iterator i = valIds.begin(); i != valIds.end(); ++i )
00558 {
00559 myobj->data.push_back( ( *i ).toDouble( &ok ) );
00560 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00561 }
00562
00563
00564 tmp = firstlinere.cap( 5 );
00565 if ( !tmp.isEmpty() )
00566 {
00567 long intId = tmp.toLong( &ok, 16 );
00568 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00569 #ifdef CABRI_DEBUG
00570 kDebug() << "+++++++++ intId: " << intId;
00571 #endif
00572 if ( intId == 0 ) myobj->intersectionId = -1;
00573 else if ( intId == 0x10000 ) myobj->intersectionId = 1;
00574 else KIG_CABRI_FILTER_PARSE_ERROR;
00575 }
00576
00577
00578 tmp = firstlinere.cap( 8 );
00579 if ( !tmp.isEmpty() )
00580 {
00581 myobj->side = tmp.toInt( &ok );
00582 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00583 }
00584
00585
00586 tmp = firstlinere.cap( 10 );
00587 if ( !extractValuesFromString( tmp, myobj->incs ) )
00588 KIG_CABRI_FILTER_PARSE_ERROR;
00589
00590 line = CabriNS::readLine( f );
00591
00592 QRegExp textMetrics( "^TP:[\\s]*([^,]+),[\\s]*([^,]+), TS:[\\s]*([^,]+),[\\s]*([^,]+)$" );
00593 bool freeText = false;
00594 while ( !line.isEmpty() )
00595 {
00596 if ( line.startsWith( '\"' ) )
00597 {
00598 QString txt = CabriNS::readText( f, line );
00599 if ( myobj->type != "Text" )
00600 myobj->name = txt;
00601 else
00602 myobj->text = txt;
00603 }
00604 else if ( line.startsWith( "NbD:" ) )
00605 {
00606
00607 }
00608 else if ( textMetrics.exactMatch( line ) )
00609 {
00610 double xa = textMetrics.cap( 1 ).toDouble( &ok );
00611 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00612 double ya = textMetrics.cap( 2 ).toDouble( &ok );
00613 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00614 double tw = textMetrics.cap( 3 ).toDouble( &ok );
00615 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00616 double th = textMetrics.cap( 4 ).toDouble( &ok );
00617 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00618 myobj->textRect = Rect( xa, ya, tw, th );
00619 }
00620 else
00621 {
00622 if ( !freeText && myobj->type == "Formula" )
00623 {
00624 myobj->text = line;
00625 freeText = true;
00626 }
00627 else
00628 readStyles( file, line, myobj );
00629 }
00630
00631 line = CabriNS::readLine( f );
00632 }
00633
00634
00635 if ( !myobj->color.isValid() )
00636 myobj->color = defaultColorForObject( myobj->type );
00637
00638 return myobj;
00639 }
00640
00641 void CabriReader_v12::decodeStyle( CabriObject* obj, Qt::PenStyle& ps, int& pointType )
00642 {
00643 CabriObject_v12* myobj = (CabriObject_v12*)obj;
00644
00645 if ( ( myobj->type == "Pt" ) || ( myobj->type == "Pt/" ) )
00646 {
00647
00648 myobj->thick *= 2;
00649 switch ( myobj->pointStyle )
00650 {
00651 case 0:
00652 {
00653 myobj->thick /= 2;
00654 break;
00655 }
00656 case 1:
00657 {
00658 pointType = 2;
00659 break;
00660 }
00661 case 2:
00662 {
00663 pointType = 1;
00664 break;
00665 }
00666 case 3:
00667 {
00668 pointType = 4;
00669 break;
00670 }
00671 case 4:
00672 {
00673 break;
00674 }
00675 }
00676 }
00677 else
00678 {
00679 if ( ( myobj->lineSegLength > 1 ) && ( myobj->lineSegLength < 6 ) &&
00680 ( myobj->lineSegSplit > 1 ) && ( myobj->lineSegSplit <= 10 ) )
00681 ps = Qt::DotLine;
00682 else if ( ( myobj->lineSegLength >= 6 ) && ( myobj->lineSegSplit > 10 ) )
00683 ps = Qt::DashLine;
00684 }
00685 }
00686
00687 QColor CabriReader_v12::translateColor( const QString& s )
00688 {
00689 initColorMap();
00690 cmit it = colormap_v12.find( s );
00691 if ( it != colormap_v12.end() ) return (*it).second;
00692
00693 kDebug() << "unknown color: " << s;
00694 return CabriReader::translateColor( s );
00695 }
00696
00697 bool CabriReader_v12::readStyles( const QString& file, const QString& line, CabriObject_v12* myobj )
00698 {
00699 #ifdef CABRI_DEBUG
00700 kDebug() << ">>>>>>>>> style line: \"" << line << "\"";
00701 #endif
00702 QStringList styles = line.split( ", ", QString::SkipEmptyParts );
00703 bool ok = true;
00704 for ( QStringList::iterator it = styles.begin(); it != styles.end(); ++it )
00705 {
00706 if ( (*it) == "invisible" )
00707 {
00708 myobj->visible = false;
00709 }
00710 else if ( (*it).startsWith( "DS:" ) )
00711 {
00712 QRegExp ticks( "DS:(\\d+)\\s(\\d+)" );
00713 if ( ticks.exactMatch( (*it) ) )
00714 {
00715 myobj->lineSegLength = ticks.cap( 1 ).toInt( &ok );
00716 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00717 myobj->lineSegSplit = ticks.cap( 2 ).toInt( &ok );
00718 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00719 }
00720 }
00721
00722 else if ( (*it).startsWith( "color:" ) )
00723 {
00724 QString color = (*it).remove( 0, 6 );
00725 myobj->color = translateColor( color );
00726 }
00727 else if ( (*it).startsWith( "fill color:" ) )
00728 {
00729 QString color = (*it).remove( 0, 11 );
00730 myobj->fillColor = translateColor( color );
00731 }
00732
00733 else if ( (*it) == "thicker" )
00734 {
00735 myobj->thick = 2;
00736 }
00737 else if ( (*it) == "thick" )
00738 {
00739 myobj->thick = 3;
00740 }
00741
00742 else if ( (*it) == "1x1" )
00743 {
00744 myobj->pointStyle = 0;
00745 }
00746 else if ( (*it) == "CIRCLE" )
00747 {
00748 myobj->pointStyle = 2;
00749 }
00750 else if ( (*it) == "TIMES" )
00751 {
00752 myobj->pointStyle = 3;
00753 }
00754 else if ( (*it) == "PLUS" )
00755 {
00756 myobj->pointStyle = 4;
00757 }
00758
00759 else if ( (*it) == "deg" )
00760 {
00761 myobj->gonio = CabriNS::CG_Deg;
00762 }
00763
00764 else if ( (*it).startsWith( "marks nb:" ) )
00765 {
00766 QString strticks = (*it).remove( 0, 9 );
00767 myobj->ticks = strticks.toInt( &ok );
00768 if ( !ok ) KIG_CABRI_FILTER_PARSE_ERROR;
00769 }
00770 #ifdef CABRI_DEBUG
00771 else
00772 {
00773 kDebug() << ">>>>>>>>> UNKNOWN STYLE STRING: \"" << *it << "\"";
00774 }
00775 #endif
00776 }
00777 return true;
00778 }