コード例 #1
0
/**
 * Loads the given fils into this graphic.
 */
bool RS_Graphic::open(const RS_String &filename, RS2::FormatType type) {
    RS_DEBUG->print("RS_Graphic::open(%s)", filename.latin1());

	bool ret = false;

    this->filename = filename;
	QFileInfo finfo(filename);
	// Construct new autosave filename by prepending # to the filename
	// part, using the same directory as the destination file.
	this->autosaveFilename = finfo.dirPath() + "/#" + finfo.fileName();

    // clean all:
    newDoc();

    // import file:
    ret = RS_FILEIO->fileImport(*this, filename, type);
		
	setModified(false);
	layerList.setModified(false);
	blockList.setModified(false);

    //cout << *((RS_Graphic*)graphic);
    //calculateBorders();
	
    RS_DEBUG->print("RS_Graphic::open(%s): OK", filename.latin1());

    return ret;
}
コード例 #2
0
ファイル: rs_settings.cpp プロジェクト: Akaur/qdraw
int RS_Settings::readNumEntry(const RS_String& key, int def, bool* ok)
{
#if QT_VERSION>=0x030000

  // lookup:
  RS_String sret = readEntryCache(key);
  if (sret==RS_String::null)
  {
    int ret;
    QSettings s(QSettings::Ini);
    s.insertSearchPath(QSettings::Windows, companyKey);

    ret = s.readNumEntry(QString("%1%2%3").arg(appKey).arg(group).arg(key),
                         def, ok);
    addToCache(key, RS_String("%1").arg(ret));
    return ret;
  }
  else
  {
    return sret.toInt();
  }
#else

  return def;
#endif

}
コード例 #3
0
/**
 * Saves this graphic with the given filename and current settings.
 */
bool RS_Graphic::saveAs(const RS_String &filename, RS2::FormatType type) {

    RS_DEBUG->print("RS_Graphic::saveAs");

    this->filename = filename;
	RS_String *oldAutosaveName = new RS_String(autosaveFilename);
	QFileInfo finfo(filename);
	// Construct new autosave filename by prepending # to the filename
	// part, using the same directory as the destination file.
	this->autosaveFilename = finfo.dirPath() + "/#" + finfo.fileName();
	this->formatType = type;

    bool ret = save();

	if (ret) {
		// save was successful, remove old autosave file
		QFile f(*oldAutosaveName);
		if (f.exists()) {
			RS_DEBUG->print("removing old autosave file %s",
							oldAutosaveName->latin1());
			f.remove();
		}
	}

	delete oldAutosaveName;

	return ret;
}
コード例 #4
0
ファイル: rs_units.cpp プロジェクト: Seablade/vec2web
/**
 * Formats the given length in fractional (barbarian) format (e.g. 5' 3 1/64").
 *
 * @param length The length in the current unit of the drawing.
 * @param unit Should be inches.
 * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
RS_String RS_Units::formatFractional(double length, RS2::Unit /*unit*/,
                                     int prec, bool /*showUnit*/) {

    RS_String ret;

    int num;            // number of complete inches (num' 7/128")
    int nominator;      // number of fractions (nominator/128)
    int denominator;    // (4/denominator)

    // sign:
    RS_String neg = "";
    if(length < 0) {
        neg = "-";
        length = fabs(length);
    }

    num = (int)floor(length);

    denominator = (int)RS_Math::pow(2, prec);
    nominator = RS_Math::round((length-num)*denominator);

    // fraction rounds up to 1:
    if (nominator==denominator) {
        nominator=0;
        denominator=0;
        ++num;
    }

    // Simplify the fraction
    if (nominator!=0 && denominator!=0) {
        int gcd = RS_Math::findGCD(nominator, denominator);
        if (gcd!=0) {
            nominator = nominator / gcd;
            denominator = denominator / gcd;
        } else {
            RS_DEBUG->print(RS_Debug::D_WARNING,
				"RS_Units::formatFractional: invalid gcd");
            nominator = 0;
            denominator = 0;
        }
    }

    if( num!=0 && nominator!=0 ) {
        ret.sprintf("%s%d %d/%d",
                    (const char*)neg.local8Bit(), num,
                    nominator, denominator);
    } else if(nominator!=0) {
        ret.sprintf("%s%d/%d",
                    (const char*)neg.local8Bit(),
                    nominator, denominator);
    } else if(num!=0) {
        ret.sprintf("%s%d",
                    (const char*)neg.local8Bit(),
                    num);
    } else {
        ret.sprintf("0");
    }

    return ret;
}
コード例 #5
0
ファイル: rs_debug.cpp プロジェクト: Akaur/qdraw
/**
 * Prints a time stamp in the format yyyyMMdd_hhmmss.
 */
void RS_Debug::timestamp() {
    RS_DateTime now = RS_DateTime::currentDateTime();
    RS_String nowStr;

#if QT_VERSION>=0x030000
		nowStr = now.toString("yyyyMMdd_hh:mm:ss:zzz ");
#else
		nowStr = now.toString();
#endif
    fprintf(stream, nowStr.latin1());
    fprintf(stream, "\n");
    fflush(stream);
}
コード例 #6
0
RS_String RS_StringCompat::replace(const RS_String& str,
                                   RS_Char c1, RS_Char c2) {

    RS_String ret = str;

    for (uint i=0; i<ret.length(); ++i) {
        if (ret.at(i)==c1) {
            ret.ref(i) = c2;
        }
    }

    return ret;
}
コード例 #7
0
void RS_ActionDrawLinePolygon2::commandEvent(RS_CommandEvent* e) {
    RS_String c = e->getCommand().lower();

    if (checkCommand("help", c)) {
        if (RS_DIALOGFACTORY!=NULL) {
            RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
                                             + getAvailableCommands().join(", "));
        }
        return;
    }

    switch (getStatus()) {
    case SetCorner1:
    case SetCorner2:
        if (checkCommand("number", c)) {
            deleteSnapper();
            deletePreview();
            clearPreview();
            lastStatus = (Status)getStatus();
            setStatus(SetNumber);
        }
        break;

    case SetNumber: {
            bool ok;
            int n = c.toInt(&ok);
            if (ok==true) {
                if (n>0 && n<10000) {
                    number = n;
                } else {
                    if (RS_DIALOGFACTORY!=NULL) {
                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
                                                            "Try 1..9999"));
                    }
                }
            } else {
                if (RS_DIALOGFACTORY!=NULL) {
                    RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression."));
                }
            }
            if (RS_DIALOGFACTORY!=NULL) {
                RS_DIALOGFACTORY->requestOptions(this, true, true);
            }
            setStatus(lastStatus);
        }
        break;

    default:
        break;
    }
}
コード例 #8
0
ファイル: dl_jww.cpp プロジェクト: LibreCAD/LibreCAD
void DL_Jww::CreateTen(DL_CreationInterface* creationInterface, CDataTen& DTen)
{
	string lName = HEX[DTen.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DTen.m_nGLayer] + "-" +
													HEX[DTen.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DTen.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));
	int width;
	if(DTen.m_nPenWidth > 26)
		width = 0;
	else
		width = DTen.m_nPenWidth;
	int color = colTable[DTen.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DTen.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DTen.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DTen.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	DL_PointData d(DTen.m_start.x, DTen.m_start.y, 0.0);
	creationInterface->addPoint(d);
#ifdef FINISHED
	RS_PointData data2(RS_Vector(0.0, 0.0));
	RS_Point*	point;

	data2.pos = RS_Vector(DTen.m_start.x, DTen.m_start.y);
	point = new RS_Point(graphic, data2);
	RS2::LineType ltype = lTable[DTen.m_nPenStyle];
	RS_Color col = colTable[DTen.m_nPenColor];
	RS2::LineWidth lw = lWidth[DTen.m_nPenWidth > 26 ? 0 :DTen.m_nPenWidth];//RS2::Width12
	point->setPen(RS_Pen(col, RS2::Width23, ltype));
	//画層設定
	RS_String lName = HEX[DTen.m_nGLayer > 0x0f ? 0 : DTen.m_nGLayer] + "-" + 
		HEX[DTen.m_nLayer > 0x0f ? 0: DTen.m_nLayer];
	if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
		RS_Layer* layer = new RS_Layer(lName);
		graphic->addLayer(layer);
	}
	point->setLayer(lName);
	// add the line to the graphic
	graphic->addEntity(point);
#ifdef DEBUG
std::cout << *point;
#endif
#endif
}
コード例 #9
0
/**
 * Activates the given layer.
 * 
 * @param notify Notify listeners.
 */
void RS_LayerList::activate(const RS_String& name, bool notify) {
    RS_DEBUG->print("RS_LayerList::activate: %s, notify: %d begin", name.latin1(), notify);

    activate(find(name), notify);
    /*
    if (activeLayer==NULL) {
        RS_DEBUG->print("activeLayer is NULL");
} else {
        RS_DEBUG->print("activeLayer is %s", activeLayer->getName().latin1());
}
    */

    RS_DEBUG->print("RS_LayerList::activate: %s end", name.latin1());
}
コード例 #10
0
ファイル: rs_units.cpp プロジェクト: Seablade/vec2web
/**
 * Formats the given length in scientific format (e.g. 2.5E7).
 *
 * @param length The length in the current unit of the drawing.
 * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
RS_String RS_Units::formatScientific(double length, RS2::Unit unit,
                                     int prec, bool showUnit) {

    RS_String ret;

    // unit appended to value (e.g. 'mm'):
    RS_String unitString = "";
    if (showUnit) {
        unitString = unitToSign(unit);
    }

    char format[128];
    sprintf(format, "%%.%dE%%s", prec);
    ret.sprintf(format, length, (const char*)unitString.local8Bit());

    return ret;
}
コード例 #11
0
ファイル: rs_units.cpp プロジェクト: Seablade/vec2web
/**
 * Formats the given length in engineering format (e.g. 5' 4.5").
 *
 * @param length The length in the current unit of the drawing.
 * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
RS_String RS_Units::formatEngineering(double length, RS2::Unit /*unit*/,
                                      int prec, bool /*showUnit*/) {
    RS_String ret;

    bool sign = (length<0.0);
    int feet = (int)floor(fabs(length)/12);
    double inches = fabs(length) - feet*12;

    RS_String sInches = RS_Math::doubleToString(inches, prec);

    if (sInches=="12") {
        feet++;
        sInches="0";
    }

    if (feet!=0) {
        ret.sprintf("%d'-%s\"", feet, (const char*)sInches.local8Bit());
    } else {
        ret.sprintf("%s\"", (const char*)sInches.local8Bit());
    }

    if (sign) {
        ret = "-" + ret;
    }

    return ret;
}
コード例 #12
0
ファイル: rs_math.cpp プロジェクト: Seablade/vec2web
/**
 * Converts a double into a string which is as short as possible
 *
 * @param value The double value
 * @param prec Precision e.g. a precision of 1 would mean that a 
 *     value of 2.12030 will be converted to "2.1". 2.000 is always just "2").
 */
RS_String RS_Math::doubleToString(double value, double prec) {
	if (prec<1.0e-12) {
		std::cerr << "RS_Math::doubleToString: invalid precision\n";
		return "";
	}

    RS_String ret;
    RS_String exaStr;
    int dotPos;
    int num = RS_Math::round(value / prec);

    exaStr = RS_Math::doubleToString(prec, 10);
    dotPos = exaStr.find('.');

    if (dotPos==-1) {
        ret.sprintf("%d", RS_Math::round(num*prec));
    } else {
        int digits = exaStr.length() - dotPos - 1;
        ret = RS_Math::doubleToString(num*prec, digits);
    }

    return ret;
}
コード例 #13
0
/**
 * Loads the given fils into this graphic.
 */
bool RS_Graphic::open(const RS_String &filename, RS2::FormatType type) {
    RS_DEBUG->print("RS_Graphic::open(%s)", filename.latin1());

	bool ret = false;

    this->filename = filename;

    // clean all:
    newDoc();

    // import file:
    ret = RS_FILEIO->fileImport(*this, filename, type);
		
	setModified(false);
	layerList.setModified(false);
	blockList.setModified(false);

    //cout << *((RS_Graphic*)graphic);
    //calculateBorders();
	
    RS_DEBUG->print("RS_Graphic::open(%s): OK", filename.latin1());

    return ret;
}
コード例 #14
0
ファイル: GeometryAdapter.cpp プロジェクト: asir6/Colt
void GeometryAdapter::AddLabel(double x, double y,
                               double slope_rad, bool useSlope,
                               MdfModel::Label* label,
                               RS_OverpostType type, bool exclude,
                               Renderer* renderer,
                               LineBuffer* lb)
{
    MdfModel::TextSymbol* text = label->GetSymbol();

    RS_String txt;
    EvalString(text->GetText(), txt);

    if (!txt.empty())
    {
        RS_TextDef def;
        ConvertTextDef(text, def);

        if (useSlope)
            def.rotation() = slope_rad * M_180PI;

        RS_LabelInfo info(x, y, 0.0, 0.0, RS_Units_Model, def);
        renderer->ProcessLabelGroup(&info, 1, txt, type, exclude, lb, text->GetScaleLimit());
    }
}
コード例 #15
0
/**
 * @return Command for triggering the given action in the currently chosen
 * language for commands.
 *
 * @param action ID of the action who's command will be returned.
 * @param num Number of the command. There might be multiple commands
 *            for the same action (e.g. 'line' and 'l')
 *
 * @return The translated command.
 */
RS2::ActionType RS_Commands::cmdToAction(const RS_String& cmd) {
    RS_String c = cmd.lower();
    RS_String full = cmd;          // full command defaults to given command
    RS2::ActionType ret = RS2::ActionNone;

	// find command:
	RS2::ActionType* retPtr = mainCommands[cmd];
	if (retPtr!=NULL) {
		ret = *retPtr;
	}
	else {
		retPtr = shortCommands[cmd];
		if (retPtr!=NULL) {
			ret = *retPtr;
		}
	}

	// find full command to confirm to user:
	RS_DictIterator<RS2::ActionType> it(mainCommands);
    for (; it.current(); ++it) {
		if (*it.current()==ret) {
			if (RS_DialogFactory::instance()!=NULL) {
				//if (RS_DIALOGFACTORY!=NULL) {
					RS_DEBUG->print("RS_Commands::cmdToAction: "
						"commandMessage");
					//RS_DIALOGFACTORY->commandMessage(tr("Command: %1")
					//	.arg(full));
					RS_DialogFactory::instance()->commandMessage(
						tr("Command: %1").arg(full));
					RS_DEBUG->print("RS_Commands::cmdToAction: "
						"commandMessage: ok");
				//}
			}
			else {
				RS_DEBUG->print("RS_Commands::cmdToAction: dialog "
				  "factory instance is NULL");
			}
			break;
		}
	}
	
	return ret;
}
コード例 #16
0
/**
 * @return translated command for the given English command.
 */
RS_String RS_Commands::command(const RS_String& cmd) {
    if (cmd=="angle") {
        return tr("angle");
    } else if (cmd=="close") {
        return tr("close");
    } else if (cmd=="chord length") {
        return tr("chord length");
    } else if (cmd=="columns") {
        return tr("columns");
    } else if (cmd=="columnspacing") {
        return tr("columnspacing");
    } else if (cmd=="factor") {
        return tr("factor");
    } else if (cmd=="length") {
        return tr("length");
    } else if (cmd=="length1") {
        return tr("length1");
    } else if (cmd=="length2") {
        return tr("length2");
    } else if (cmd=="number") {
        return tr("number");
    } else if (cmd=="radius") {
        return tr("radius");
    } else if (cmd=="rows") {
        return tr("rows");
    } else if (cmd=="rowspacing") {
        return tr("rowspacing");
    } else if (cmd=="text") {
        return tr("text");
    } else if (cmd=="through") {
        return tr("through");
    } else if (cmd=="trim") {
        return tr("trim");
    } else if (cmd=="undo") {
        return tr("undo");
    }

    RS_DEBUG->print(RS_Debug::D_WARNING,
		"RS_Commands::command: command '%s' unknown", cmd.latin1());
    return "";
}
コード例 #17
0
ファイル: rs_simplepython.cpp プロジェクト: Akaur/qdraw
/**
 * Launches the given script.
 */
int RS_SimplePython::launch(const RS_String& script) {
    long answer;
    PyObject *modname, *mod, *mdict, *func, *rslt;
    //Py_SetProgramName(argv[0]);
    Py_Initialize();
    init_pyextension();
    modname = PyString_FromString(script);
    mod = PyImport_Import(modname);
    if (mod) {
        //printf( "mod\n");
        mdict = PyModule_GetDict(mod);

        // Borrowed reference to start function
        func = PyDict_GetItemString(mdict, "start");
        if (func) {
            //printf( "func\n");
            if (PyCallable_Check(func)) {
                //printf("calling..\n");
                rslt = PyObject_CallFunction(func, "(s)", "noparam");
                //printf("calling ok\n");
                if (rslt) {
                    //printf("c: rslt\n");
                    answer = PyInt_AsLong(rslt);
                    //printf("c: answer is: %ld\n", answer);
                    Py_XDECREF(rslt);
                }
            }
        } else {
            printf("no such function: start\n");
        }
        Py_XDECREF(mod);
    } else {
        printf("no such module: %s\n", script.latin1());
    }
    Py_XDECREF(modname);
    Py_Finalize();
    return 0;
}
コード例 #18
0
RS_String RS_StringCompat::replace(const RS_String& str,
                                   const RS_String& s1, const RS_String& s2) {

    if (s1.isEmpty()) {
        return str;
    }

    RS_String ret = "";

    for (uint i=0; i<str.length(); ++i) {
        if (str.mid(i, s1.length())==s1) {
            ret += s2;
			i += s1.length()-1;
        } else {
            ret += str.at(i);
        }
    }

    return ret;
}
コード例 #19
0
ファイル: rs_units.cpp プロジェクト: Seablade/vec2web
/**
 * Formats the given length in architectural format (e.g. 5' 4 1/2").
 *
 * @param length The length in the current unit of the drawing.
 * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125)
 & @param showUnit Append unit to the value.
 */
RS_String RS_Units::formatArchitectural(double length, RS2::Unit /*unit*/,
                                        int prec, bool showUnit) {
    RS_String ret;
    bool neg = (length<0.0);

    int feet = (int)floor(fabs(length)/12);
    double inches = fabs(length) - feet*12;

    RS_String sInches = formatFractional(inches, RS2::Inch, prec, showUnit);

    if (sInches=="12") {
        feet++;
        sInches = "0";
    }

    if (neg) {
        ret.sprintf("-%d'-%s\"", feet, (const char*)sInches.local8Bit());
    } else {
        ret.sprintf("%d'-%s\"", feet, (const char*)sInches.local8Bit());
    }

    return ret;
}
コード例 #20
0
ファイル: rs_math.cpp プロジェクト: Seablade/vec2web
/**
 * Converts a double into a string which is as short as possible.
 *
 * @param value The double value
 * @param prec Precision
 */
RS_String RS_Math::doubleToString(double value, int prec) {
    RS_String valStr;

    valStr.setNum(value, 'f', prec);

    if(valStr.contains('.')) {
        // Remove zeros at the end:
        while (valStr.at(valStr.length()-1)=='0') {
            valStr.truncate(valStr.length()-1);
        }

        if(valStr.at(valStr.length()-1)=='.') {
            valStr.truncate(valStr.length()-1);
        }
    }

    return valStr;
}
コード例 #21
0
ファイル: rs_utility.cpp プロジェクト: Akaur/qdraw
/**
 * Converts a double to a string cutting away unnecessary 0's.
 * e.g. 2.70000  -> 2.7
 */
RS_String RS_Utility::doubleToString(double value, int precision) {
    RS_String ret;

    ret.setNum(value, 'f', precision);

    if(ret.contains('.')) {
        // remove trailing zeros:
        while(ret.at(ret.length()-1)=='0') {
            ret.truncate(ret.length()-1);
        }

        // remove trailing .
        if(ret.at(ret.length()-1)=='.') {
            ret.truncate(ret.length()-1);
        }
    }

    return ret;
}
コード例 #22
0
ファイル: dl_jww.cpp プロジェクト: LibreCAD/LibreCAD
void DL_Jww::CreateMoji(DL_CreationInterface* creationInterface, CDataMoji& DMoji)
{
	string lName = HEX[DMoji.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DMoji.m_nGLayer] + "-" +
													HEX[DMoji.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DMoji.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));

	int width;
	if(DMoji.m_nPenWidth > 26)
		width = 0;
	else
		width = DMoji.m_nPenWidth;
	int color = colTable[DMoji.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DMoji.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DMoji.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DMoji.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	DL_TextData d(
		// insertion point
		DMoji.m_start.x, DMoji.m_start.y, 0.0,
		// alignment point
		0.0, 0.0, 0.0,
		// height
		DMoji.m_dSizeY,
		// x scale
		1.0,
		// generation flags
		0,
		// h just
		0,
		// v just
		0,
		// text
		DMoji.m_string,
		// style
		string("japanese"),
		// angle
		DMoji.m_degKakudo / 180.0 * M_PI);

	creationInterface->addText(d);
#ifdef FINISHED
	QTextCodec* codec = QTextCodec::codecForName("SJIS");
	RS_TextData data3(RS_Vector(0.0, 0.0),
				10,//double height,
				10,//double width,
				RS2::VAlignMiddle,
				RS2::HAlignCenter,
				RS2::LeftToRight,
				RS2::AtLeast,
				1.0,//double lineSpacingFactor,
				RS_String(""),//const RS_String& text,
				RS_String(""),
				0.0,//double angle,
				RS2::Update);
	RS_Text*	text;
	data3.insertionPoint = RS_Vector(DMoji.m_start.x, DMoji.m_start.y);
	data3.height = DMoji.m_dSizeY;
	data3.width = DMoji.m_dSizeX;
	data3.valign = RS2::VAlignBottom;//VAlignMiddle;
	data3.halign = RS2::HAlignLeft;//HAlignCenter;
	data3.drawingDirection = RS2::LeftToRight;
	data3.lineSpacingStyle = RS2::Exact;
	data3.lineSpacingFactor = DMoji.m_dKankaku;//1.0;
	//コード変換
	size_t left = DMoji.m_string.length();
	char* sjis = (char *)DMoji.m_string.c_str();
	char buf[200];
	//memset(buf, NULL, 1000);
	char* p = buf;
	size_t bufleft = 200;
#ifdef _WINDOWS
	// エンコーディングの変換:iconvを使う場合
	iconv_t cd = iconv_open(UTF8_CES, SHIFTJIS_CES);
#ifdef	DEBUG
printf("sjis = %x, p = %x\n", sjis, p);
#endif
	size_t r = iconv(cd, (const char **)(&sjis), &left, &p, &bufleft);//const_cast<char**>
#ifdef	DEBUG
printf("sjis = %x, p = %x\n", sjis, p);
printf("sjis = %x %x %x %x, p = %x %x %x %x\n", sjis[0],sjis[1],sjis[2],sjis[3], buf[0],buf[1],buf[2],buf[3]);
printf("r = %d, left = %d, bufleft = %d\n", r, left, bufleft);
#endif
	*p = '\0';
	iconv_close(cd);
#else
//	int ires = SJIS2UTF8N(sjis,buf,bufleft);
	int nBytesOut;
	strcpy(buf,(const char *)CUnicodeF::sjis_to_euc((const unsigned char *)sjis/*, &nBytesOut*/));
//	QTextCodec* codec = QTextCodec::codecForName("eucJP");
//	data3.text = codec->toUnicode(buf);
#endif
//	data3.text = codec->toUnicode(sjis);
	data3.text = RS_String::fromUtf8(buf);
	data3.style = RS_String("japanese-euc");
	data3.angle = DMoji.m_degKakudo / 180.0 * M_PI;
#ifdef DEBUG
RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
#endif
	data3.updateMode = RS2::Update;
	//jwDWORD m_nMojiShu;//文字種(斜体文字は20000、ボールド体は10000を加えた数値)

	text = new RS_Text(graphic, data3);
	RS2::LineType ltype = lTable[DMoji.m_nPenStyle];
	RS_Color col = colTable[DMoji.m_nPenColor];
	RS2::LineWidth lw = lWidth[DMoji.m_nPenWidth > 26 ? 0 : DMoji.m_nPenWidth];//RS2::Width12
	text->setPen(RS_Pen(col, RS2::Width08, ltype));

	//画層設定
	RS_String lName = HEX[DMoji.m_nGLayer > 0x0f ? 0: DMoji.m_nGLayer] + "-" +
		HEX[DMoji.m_nLayer > 0x0f ? 0 : DMoji.m_nLayer];
	if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
		RS_Layer* layer = new RS_Layer(lName);
		graphic->addLayer(layer);
	}
	text->setLayer(lName);
	// add the line to the graphic
	graphic->addEntity(text);
#ifdef DEBUG
std::cout << data3.height << "  " << data3.width << std::endl;
std::cout << *text;
#endif
#endif
}
コード例 #23
0
ファイル: rs_debug.cpp プロジェクト: Akaur/qdraw
/**
 * Prints the unicode for every character in the given string.
 */
void RS_Debug::printUnicode(const RS_String& text) {
    for (int i=0; i<(int)text.length(); i++) {
        print("[%X] %c", text.at(i).unicode(), text.at(i).latin1());
    }
}
コード例 #24
0
ファイル: dl_jww.cpp プロジェクト: LibreCAD/LibreCAD
void DL_Jww::CreateEnko(DL_CreationInterface* creationInterface, CDataEnko& DEnko)
{
	string lName = HEX[DEnko.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DEnko.m_nGLayer] + "-" +
													HEX[DEnko.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DEnko.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));

	int width;
	if(DEnko.m_nPenWidth > 26)
		width = 0;
	else
		width = DEnko.m_nPenWidth;
	int color = colTable[DEnko.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DEnko.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DEnko.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DEnko.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	double angle1, angle2;
	//正円
	if(DEnko.m_bZenEnFlg){
		if(DEnko.m_dHenpeiRitsu == 1.0){
			DL_CircleData d(DEnko.m_start.x, DEnko.m_start.y, 0.0, DEnko.m_dHankei);
			creationInterface->addCircle(d);
		}else{
			double angle1, angle2;
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			//楕円
			DL_EllipseData d(DEnko.m_start.x, DEnko.m_start.y, 0.0,
							DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku), 0.0,
							DEnko.m_dHenpeiRitsu,
							angle1, angle2);

			creationInterface->addEllipse(d);
		}
	}else{
		if(DEnko.m_dHenpeiRitsu == 1.0){
			//円弧
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			DL_ArcData d(DEnko.m_start.x, DEnko.m_start.y, 0.0,
					DEnko.m_dHankei,
					Deg(angle1),
					Deg(angle2));

			creationInterface->addArc(d);
		}else{
			double angle1, angle2;
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			//楕円
			DL_EllipseData d(DEnko.m_start.x, DEnko.m_start.y, 0.0,
							DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku), 0.0,
							DEnko.m_dHenpeiRitsu,
							angle1, angle2);

			creationInterface->addEllipse(d);
		}
	}
#ifdef FINISHED
	RS_CircleData data1(RS_Vector(0.0, 0.0), 0.0);
	RS_Circle* circle;
	RS_ArcData arc_data(RS_Vector(0.0, 0.0), 0.0, 0.0, 0.0, false);
	RS_Arc* arc;
	RS_Ellipse* elps;
	//正円
	if(DEnko.m_bZenEnFlg){
		if(DEnko.m_dHenpeiRitsu == 1.0){
			data1.center = RS_Vector(DEnko.m_start.x, DEnko.m_start.y);
			data1.radius = DEnko.m_dHankei;
			circle = new RS_Circle(graphic, data1);
			RS2::LineType ltype = lTable[DEnko.m_nPenStyle];
			RS_Color col = colTable[DEnko.m_nPenColor];
			RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12
			circle->setPen(RS_Pen(col, lw, ltype));

			RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" +
				HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer];
			if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
				RS_Layer* layer = new RS_Layer(lName);
				graphic->addLayer(layer);
			}
			circle->setLayer(lName);
			// add the line to the graphic
			graphic->addEntity(circle);
#ifdef DEBUG
std::cout << *circle;
#endif
		}else{
			//楕円
			double angle1, angle2;
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			RS_EllipseData elps_data(RS_Vector(DEnko.m_start.x, DEnko.m_start.y),
									RS_Vector(DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku)),
									DEnko.m_dHenpeiRitsu,
									angle1, angle2, false);
			elps = new RS_Ellipse(graphic, elps_data);
			RS2::LineType ltype = lTable[DEnko.m_nPenStyle];
			RS_Color col = colTable[DEnko.m_nPenColor];
			RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12
			elps->setPen(RS_Pen(col, lw, ltype));

			RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" +
				HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer];
			if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
				RS_Layer* layer = new RS_Layer(lName);
				graphic->addLayer(layer);
			}
			elps->setLayer(lName);
			// add the line to the graphic
			graphic->addEntity(elps);
		}
	}else{
		//円弧
		arc_data.center = RS_Vector(DEnko.m_start.x, DEnko.m_start.y);
		arc_data.radius = DEnko.m_dHankei;
		if(DEnko.m_radEnkoKaku > 0.0){
			arc_data.angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
			arc_data.angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
		}else{
			arc_data.angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
			arc_data.angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
		}
		if( arc_data.angle2 <= arc_data.angle1 )
			arc_data.angle1 = arc_data.angle1 - M_PI * 2.0;
		arc_data.angle1 = Deg(arc_data.angle1);
		arc_data.angle2 = Deg(arc_data.angle2);
		arc_data.reversed = false;
		arc = new RS_Arc(graphic, arc_data);
		RS2::LineType ltype = lTable[DEnko.m_nPenStyle];
		RS_Color col = colTable[DEnko.m_nPenColor];
		RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12
		arc->setPen(RS_Pen(col, lw, ltype));

		RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" +
			HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer];
		if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
			RS_Layer* layer = new RS_Layer(lName);
			graphic->addLayer(layer);
		}
		arc->setLayer(lName);
		// add the line to the graphic
		graphic->addEntity(arc);
	}
#endif
}
コード例 #25
0
ファイル: dl_jww.cpp プロジェクト: LibreCAD/LibreCAD
void DL_Jww::CreateSen(DL_CreationInterface* creationInterface, CDataSen& DSen)
{
	string lName = HEX[DSen.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DSen.m_nGLayer] + "-" +
													HEX[DSen.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DSen.m_nLayer];
	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));
//#ifdef	DEBUG
if(DSen.m_nPenStyle > ArraySize(lTable)-1)
	std::cout << "線種番号 " << (jwWORD)DSen.m_nPenStyle << std::endl;   //線種番号
if(DSen.m_nPenColor > ArraySize(colTable)-1)
	std::cout << "線色番号 " << (jwWORD)DSen.m_nPenColor << std::endl;   //線色番号
if(DSen.m_nPenWidth > 26)
	std::cout << "線色幅 " << (jwWORD)DSen.m_nPenWidth << std::endl;//線色幅
//#endif
	int width;
	if(DSen.m_nPenWidth > 26)
		width = 0;
	else
		width = DSen.m_nPenWidth;
	int color = colTable[DSen.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DSen.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DSen.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DSen.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );
	// correct some impossible attributes for layers:
/*
	attrib = creationInterface->getAttributes();
	if (attrib.getColor()==256 || attrib.getColor()==0) {
		attrib.setColor(7);
	}
	if (attrib.getWidth()<0) {
		attrib.setWidth(1);
	}
	if (!strcasecmp(attrib.getLineType().c_str(), "BYLAYER") ||
			!strcasecmp(attrib.getLineType().c_str(), "BYBLOCK")) {
		attrib.setLineType("CONTINUOUS");
	}
*/
	DL_LineData d(DSen.m_start.x,
				DSen.m_start.y,
				0.0,
				DSen.m_end.x,
				DSen.m_end.y,
				0.0);

	creationInterface->addLine(d);

#ifdef FINISHED
	RS_LineData data(RS_Vector(0.0, 0.0), RS_Vector(0.0, 0.0));
	RS_Line* line;

	data.startpoint = RS_Vector(DSen.m_start.x, DSen.m_start.y);
	data.endpoint = RS_Vector(DSen.m_end.x, DSen.m_end.y);
	line = new RS_Line(graphic, data);
	RS2::LineType ltype = lTable[DSen.m_nPenStyle];
	RS_Color col = colTable[DSen.m_nPenColor];
	RS2::LineWidth lw = lWidth[DSen.m_nPenWidth>26 ? 0 : DSen.m_nPenWidth];
	line->setPen(RS_Pen(col, lw, ltype));
			//画層設定
//画層
// m_nGLayer-m_nLayer
//_0-0_ から_0-F_
//	 ...
//_F-0_ から_F-F_
	RS_String lName = HEX[DSen.m_nGLayer > 0x0f ? 0: DSen.m_nGLayer] + "-" +
		HEX[DSen.m_nLayer > 0x0f ? 0: DSen.m_nLayer];
	if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
cout << jwdoc->vSen[i].m_nGLayer << " " << jwdoc->vSen[i].m_nLayer << endl;
std::cout << lName.ascii() << std::endl;
#endif
		RS_Layer* layer = new RS_Layer(lName);
		graphic->addLayer(layer);
	}
	line->setLayer(lName);
#ifdef	DEBUG
std::cout << "線種番号 " << (jwWORD)DSen.m_nPenStyle << std::endl;   //線種番号
std::cout << "線色番号 " << (jwWORD)DSen.m_nPenColor << std::endl;   //線色番号
std::cout << "線色幅 " << (jwWORD)DSen.m_nPenWidth << std::endl;//線色幅
#endif

	// add the line to the graphic
	graphic->addEntity(line);
	std::cout << *line;
#endif
}
コード例 #26
0
ファイル: PolylineAdapter.cpp プロジェクト: asir6/Colt
void PolylineAdapter::Stylize(Renderer*                   renderer,
                              RS_FeatureReader*           features,
                              bool                        initialPass,
                              FdoExpressionEngine*        exec,
                              LineBuffer*                 geometry,
                              MdfModel::FeatureTypeStyle* style,
                              const MdfModel::MdfString*  tooltip,
                              const MdfModel::MdfString*  url,
                              RS_ElevationSettings*       elevSettings,
                              CSysTransformer*            /*layer2mapxformer*/)
{
    m_exec = exec;

    // no need to do anything if the style is not a line style, so quit
    if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(style) != FeatureTypeStyleVisitor::ftsLine)
        return;

    //-------------------------------------------------------
    // determine the rule for the feature
    //-------------------------------------------------------

    MdfModel::RuleCollection* lrc = style->GetRules();
    MdfModel::LineRule* rule = NULL;

    for (int i=0; i<lrc->GetCount(); ++i)
    {
        rule = static_cast<MdfModel::LineRule*>(lrc->GetAt(i));

        // apply any filter on the rule - if it fails move to the next rule
        if (!ExecFdoFilter(&rule->GetFilter()))
        {
            // don't stylize with failed rule
            rule = NULL;
            continue;
        }

        break;
    }

    if (!rule)
        return;

    MdfModel::LineSymbolizationCollection* lsymc = rule->GetSymbolizations();
    if (lsymc == NULL)
        return;

    int nSyms = lsymc->GetCount();

    //-------------------------------------------------------
    // evaluate all the styles once
    //-------------------------------------------------------

    // temporary array used to store pointers to each evaluated style
    RS_LineStroke** ppStrokes = (RS_LineStroke**)alloca(nSyms * sizeof(RS_LineStroke*));
    if (!ppStrokes)
        return;

    size_t tempIndex = 0;
    for (int i=0; i<nSyms; ++i)
    {
        MdfModel::LineSymbolization2D* lsym = lsymc->GetAt(i);

        // don't render if there's no symbolization
        if (lsym == NULL)
        {
            ppStrokes[i] = NULL;
            continue;
        }

        // quick check if style is already cached
        RS_LineStroke* cachedStyle = m_hLineSymCache[lsym];
        if (cachedStyle)
        {
            ppStrokes[i] = cachedStyle;
        }
        else
        {
            // if not, then we need to either cache or evaluate it

            // make sure the vector has a style in the slot we need
            if (tempIndex >= m_lineSyms.size())
            {
                _ASSERT(tempIndex == m_lineSyms.size());

                // allocate a new style and add it to the vector
                m_lineSyms.push_back(new RS_LineStroke());
            }

            // use the existing style in the vector
            ppStrokes[i] = m_lineSyms[tempIndex];
            ObtainStyle(lsym, *ppStrokes[i]);

            ++tempIndex;
        }
    }

    //-------------------------------------------------------
    // compute the clip offset from the styles
    //-------------------------------------------------------

    double clipOffsetWU = 0.0;  // in mapping units

    bool bClip      = renderer->RequiresClipping();
    bool bLabelClip = renderer->RequiresLabelClipping();

    if (bClip || bLabelClip)
    {
        double mapScale = renderer->GetMapScale();

        double clipOffsetMeters = 0.0;  // in device units
        for (int i=0; i<nSyms; ++i)
        {
            if (ppStrokes[i])
            {
                double styleClipOffset = GetClipOffset(*ppStrokes[i], mapScale);
                clipOffsetMeters = rs_max(styleClipOffset, clipOffsetMeters);
            }
        }

        // add one pixel's worth to handle any roundoff
        clipOffsetMeters += METERS_PER_INCH / renderer->GetDpi();

        // limit the offset to something reasonable
        if (clipOffsetMeters > MAX_CLIPOFFSET_IN_METERS)
            clipOffsetMeters = MAX_CLIPOFFSET_IN_METERS;

        // convert to mapping units
        clipOffsetWU = clipOffsetMeters * mapScale / renderer->GetMetersPerUnit();
    }

    //-------------------------------------------------------
    // prepare the geometry on which to apply the style
    //-------------------------------------------------------

    LineBuffer* lb = geometry;
    std::auto_ptr<LineBuffer> spClipLB;

    if (bClip)
    {
        // the clip region is the map request extents expanded by the offset
        RS_Bounds clip = renderer->GetBounds();
        clip.minx -= clipOffsetWU;
        clip.miny -= clipOffsetWU;
        clip.maxx += clipOffsetWU;
        clip.maxy += clipOffsetWU;

        // clip geometry to given extents
        LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool);
        if (lbc != lb)
        {
            // if the clipped buffer is NULL (completely clipped) just move on to
            // the next feature
            if (!lbc)
                return;

            // otherwise continue processing with the clipped buffer
            lb = lbc;
            if (lb != geometry)
                spClipLB.reset(lb);
        }
    }

    //-------------------------------------------------------
    // do the StartFeature notification
    //-------------------------------------------------------

    RS_String tip; //TODO: this should be quick since we are not assigning
    RS_String eurl;
    const RS_String &theme = rule->GetLegendLabel();

    if (tooltip && !tooltip->empty())
        EvalString(*tooltip, tip);
    if (url && !url->empty())
        EvalString(*url, eurl);

    // elevation settings
    RS_ElevationType elevType = RS_ElevationType_RelativeToGround;
    double zOffset = 0.0;
    double zExtrusion = 0.0;
    GetElevationParams(elevSettings, zOffset, zExtrusion, elevType);

    renderer->StartFeature(features, initialPass,
                           tip.empty()? NULL : &tip,
                           eurl.empty()? NULL : &eurl,
                           theme.empty()? NULL : &theme,
                           zOffset, zExtrusion, elevType);

    //-------------------------------------------------------
    // apply the style to the geometry using the renderer
    //-------------------------------------------------------

    for (int i=0; i<nSyms; ++i)
    {
        if (ppStrokes[i])
            renderer->ProcessPolyline(lb, *ppStrokes[i]);
    }

    //-------------------------------------------------------
    // do labeling if needed
    //-------------------------------------------------------

    MdfModel::Label* label = rule->GetLabel();
    if (label && label->GetSymbol())
    {
        // Make sure the geometry is clipped if label clipping is specified.
        // If bClip is true then the geometry is already clipped.
        if (!bClip && bLabelClip)
        {
            // the clip region is the map request extents expanded by the offset
            RS_Bounds clip = renderer->GetBounds();
            clip.minx -= clipOffsetWU;
            clip.miny -= clipOffsetWU;
            clip.maxx += clipOffsetWU;
            clip.maxy += clipOffsetWU;

            LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool);
            if (lbc != lb)
            {
                // if the clipped buffer is NULL (completely clipped) just move on to
                // the next feature
                if (!lbc)
                    return;

                // otherwise continue processing with the clipped buffer
                lb = lbc;
                if (lb != geometry)
                    spClipLB.reset(lb);
            }
        }

        double cx = std::numeric_limits<double>::quiet_NaN();
        double cy = std::numeric_limits<double>::quiet_NaN();
        double slope_rad = 0.0;

        // multi should work for simple polylines too
        lb->Centroid(LineBuffer::ctLine, &cx, &cy, &slope_rad);

        if (!_isnan(cx) && !_isnan(cy))
            AddLabel(cx, cy, slope_rad, true, label, RS_OverpostType_AllFit, true, renderer, label->GetSymbol()->IsAdvancedPlacement()? lb : NULL);
    }

    // free clipped line buffer if the geometry was clipped
    if (spClipLB.get())
        LineBufferPool::FreeLineBuffer(m_lbPool, spClipLB.release());
}
コード例 #27
0
void PolygonAdapter::Stylize(Renderer*                   renderer,
                             RS_FeatureReader*           features,
                             bool                        initialPass,
                             SE_Evaluator*               eval,
                             LineBuffer*                 geometry,
                             MdfModel::FeatureTypeStyle* style,
                             const MdfModel::MdfString*  tooltip,
                             const MdfModel::MdfString*  url,
                             RS_ElevationSettings*       elevSettings,
                             CSysTransformer*            /*layer2mapxformer*/)
{
    m_eval = eval;

    // no need to do anything if the style is not an area style, so quit
    if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(style) != FeatureTypeStyleVisitor::ftsArea)
        return;

    //-------------------------------------------------------
    // determine the rule for the feature
    //-------------------------------------------------------

    MdfModel::RuleCollection* arc = style->GetRules();
    MdfModel::AreaRule* rule = NULL;

    for (int i=0; i<arc->GetCount(); ++i)
    {
        rule = static_cast<MdfModel::AreaRule*>(arc->GetAt(i));

        // apply any filter on the rule - if it fails move to the next rule
        if (!ExecFilter(&rule->GetFilter()))
        {
            // don't stylize with failed rule
            rule = NULL;
            continue;
        }

        break;
    }

    if (!rule)
        return;

    MdfModel::AreaSymbolization2D* asym = rule->GetSymbolization();
    if (asym == NULL)
        return;

    //-------------------------------------------------------
    // evaluate the style to use
    //-------------------------------------------------------

    // quick check if style is already cached
    RS_FillStyle* fillStyle = m_hAreaSymCache[asym];
    if (!fillStyle)
    {
        // if not, then we need to either cache or evaluate it
        fillStyle = &m_fillStyle;
        ObtainStyle(asym, *fillStyle);
    }

    //-------------------------------------------------------
    // compute the clip offset from the styles
    //-------------------------------------------------------

    double clipOffsetWU = 0.0;  // in mapping units

    bool bClip      = renderer->RequiresClipping();
    bool bLabelClip = renderer->RequiresLabelClipping();

    if (bClip || bLabelClip)
    {
        double mapScale = renderer->GetMapScale();

        // in meters in device units
        double clipOffsetMeters = GetClipOffset(fillStyle->outline(), mapScale);

        // add one pixel's worth to handle any roundoff
        clipOffsetMeters += METERS_PER_INCH / renderer->GetDpi();

        // limit the offset to something reasonable
        if (clipOffsetMeters > MAX_CLIPOFFSET_IN_METERS)
            clipOffsetMeters = MAX_CLIPOFFSET_IN_METERS;

        // convert to mapping units
        clipOffsetWU = clipOffsetMeters * mapScale / renderer->GetMetersPerUnit();
    }

    //-------------------------------------------------------
    // prepare the geometry on which to apply the style
    //-------------------------------------------------------

    LineBuffer* lb = geometry;
    std::auto_ptr<LineBuffer> spClipLB;

    if (bClip)
    {
        // the clip region is the map request extents expanded by the offset
        RS_Bounds clip = renderer->GetBounds();
        clip.minx -= clipOffsetWU;
        clip.miny -= clipOffsetWU;
        clip.maxx += clipOffsetWU;
        clip.maxy += clipOffsetWU;

        // clip geometry to given extents
        LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool);
        if (lbc != lb)
        {
            // if the clipped buffer is NULL (completely clipped) just move on to
            // the next feature
            if (!lbc)
                return;

            // otherwise continue processing with the clipped buffer
            lb = lbc;
            if (lb != geometry)
                spClipLB.reset(lb);
        }
    }

    //-------------------------------------------------------
    // do the StartFeature notification
    //-------------------------------------------------------

    RS_String tip; //TODO: this should be quick since we are not assigning
    RS_String eurl;
    const RS_String &theme = rule->GetLegendLabel();

    if (tooltip && !tooltip->empty())
        EvalString(*tooltip, tip);
    if (url && !url->empty())
        EvalString(*url, eurl);

    // elevation settings
    RS_ElevationType elevType = RS_ElevationType_RelativeToGround;
    double zOffset = 0.0;
    double zExtrusion = 0.0;
    GetElevationParams(elevSettings, zOffset, zExtrusion, elevType);

    renderer->StartFeature(features, initialPass,
                           tip.empty()? NULL : &tip,
                           eurl.empty()? NULL : &eurl,
                           theme.empty()? NULL : &theme,
                           zOffset, zExtrusion, elevType);

    //-------------------------------------------------------
    // apply the style to the geometry using the renderer
    //-------------------------------------------------------

    renderer->ProcessPolygon(lb, *fillStyle);

    //-------------------------------------------------------
    // do labeling if needed
    //-------------------------------------------------------

    MdfModel::Label* label = rule->GetLabel();
    if (label && label->GetSymbol())
    {
        // Make sure the geometry is clipped if label clipping is specified.
        // If bClip is true then the geometry is already clipped.
        if (!bClip && bLabelClip)
        {
            // the clip region is the map request extents expanded by the offset
            RS_Bounds clip = renderer->GetBounds();
            clip.minx -= clipOffsetWU;
            clip.miny -= clipOffsetWU;
            clip.maxx += clipOffsetWU;
            clip.maxy += clipOffsetWU;

            LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool);
            if (lbc != lb)
            {
                // if the clipped buffer is NULL (completely clipped) just move on to
                // the next feature
                if (!lbc)
                    return;

                // otherwise continue processing with the clipped buffer
                lb = lbc;
                if (lb != geometry)
                    spClipLB.reset(lb);
            }
        }

        double cx = std::numeric_limits<double>::quiet_NaN();
        double cy = std::numeric_limits<double>::quiet_NaN();
        double dummy;

        // multi should work for simple polygons too
        lb->Centroid(LineBuffer::ctArea, &cx, &cy, &dummy);

        if (!_isnan(cx) && !_isnan(cy))
            AddLabel(cx, cy, 0.0, false, label, RS_OverpostType_AllFit, true, renderer, lb);
    }

    // free clipped line buffer if the geometry was clipped
    if (spClipLB.get())
        LineBufferPool::FreeLineBuffer(m_lbPool, spClipLB.release());
}
コード例 #28
0
/**
 * Gets the action for the given keycode. A keycode is a sequence
 * of key-strokes that is entered like hotkeys.
 */
RS2::ActionType RS_Commands::keycodeToAction(const RS_String& code) {
    RS_String c = code.lower();
    RS2::ActionType ret = RS2::ActionNone;

    // draw:
    if (c==tr("po", "point")) {
        ret = RS2::ActionDrawPoint;
    } else if (c==tr("li", "line")) {
        ret = RS2::ActionDrawLine;
    } else if (c==tr("pa", "parallel")) {
        ret = RS2::ActionDrawLine;
    } else if (c==tr("re", "rectangle")) {
        ret = RS2::ActionDrawLineRectangle;
    } else if (c==tr("rp", "regular polygon")) {
        ret = RS2::ActionDrawLinePolygon;
    } else if (c==tr("ci", "circle")) {
        ret = RS2::ActionDrawCircle;
    } else if (c==tr("c2", "2 point circle")) {
        ret = RS2::ActionDrawCircle2P;
    } else if (c==tr("c3", "3 point circle")) {
        ret = RS2::ActionDrawCircle3P;
    } else if (c==tr("ar", "arc")) {
        ret = RS2::ActionDrawArc;
    } else if (c==tr("a3", "3 point arc")) {
        ret = RS2::ActionDrawArc3P;
    } else if (c==tr("ep", "ellipse")) {
        ret = RS2::ActionDrawEllipseAxis;
    } else if (c==tr("tx", "text") || c==tr("mt", "text")) {
        ret = RS2::ActionDrawText;
    }

	// dimensions:
    else if (c==tr("da", "dimension - aligned")) {
        ret = RS2::ActionDimAligned;
    } else if (c==tr("dh", "dimension - horizontal")) {
        ret = RS2::ActionDimLinearHor;
    } else if (c==tr("dv", "dimension - vertical")) {
        ret = RS2::ActionDimLinearVer;
    } else if (c==tr("dr", "dimension - linear")) {
        ret = RS2::ActionDimLinear;
    } else if (c==tr("ld", "dimension - leader")) {
        ret = RS2::ActionDimLeader;
	}

    // zoom:
    else if (c==tr("rd", "redraw")) {
        ret = RS2::ActionZoomRedraw;
    } else if (c==tr("zw", "zoom - window")) {
        ret = RS2::ActionZoomWindow;
    } else if (c==tr("za", "zoom - auto")) {
        ret = RS2::ActionZoomAuto;
    } else if (c==tr("zi", "zoom - in")) {
        ret = RS2::ActionZoomIn;
    } else if (c==tr("zo", "zoom - out")) {
        ret = RS2::ActionZoomOut;
    } else if (c==tr("zp", "zoom - pan")) {
        ret = RS2::ActionZoomPan;
    } else if (c==tr("zv", "zoom - previous")) {
        ret = RS2::ActionZoomPrevious;
    }

	// snap:
	else if (c==tr("os", "snap - none")) {
		ret = RS2::ActionSnapFree;
	} else if (c==tr("sg", "snap - grid")) {
		ret = RS2::ActionSnapGrid;
	} else if (c==tr("se", "snap - end")) {
		ret = RS2::ActionSnapEndpoint;
	} else if (c==tr("si", "snap - intersection")) {
		ret = RS2::ActionSnapIntersection;
	} else if (c==tr("sn", "snap - center")) {
		ret = RS2::ActionSnapCenter;
	} else if (c==tr("sm", "snap - middle")) {
		ret = RS2::ActionSnapMiddle;
	} else if (c==tr("sn", "snap - nearest")) {
		ret = RS2::ActionSnapMiddle;
	} else if (c==tr("np", "snap - nearest point")) {
		ret = RS2::ActionSnapOnEntity;
	}

	// layer:
	else if (c==tr("fr*", "layers - freeze all")) {
		ret = RS2::ActionLayersFreezeAll;
	} else if (c==tr("th*", "layers - defreeze all")) {
		ret = RS2::ActionLayersDefreezeAll;
	}

	// selection:
	else if (c==tr("tn", "Deselect all")) {
		ret = RS2::ActionDeselectAll;
	}

	// modify:
	else if (c==tr("ch", "modify - bevel (chamfer)")) {
		ret = RS2::ActionModifyBevel;
	} else if (c==tr("tm", "modify - multi trim (extend)")) {
		ret = RS2::ActionModifyTrim2;
	} else if (c==tr("xt", "modify - trim (extend)")) {
		ret = RS2::ActionModifyTrim;
	} else if (c==tr("rm", "modify - trim")) {
		ret = RS2::ActionModifyTrim;
	} else if (c==tr("mv", "modify - move")) {
		ret = RS2::ActionModifyMove;
	} else if (c==tr("mi", "modify - mirror")) {
		ret = RS2::ActionModifyMirror;
	} else if (c==tr("ro", "modify - rotate")) {
		ret = RS2::ActionModifyRotate;
	} else if (c==tr("sz", "modify - scale")) {
		ret = RS2::ActionModifyMove;
	} else if (c==tr("ss", "modify - stretch")) {
		ret = RS2::ActionModifyStretch;
	} else if (c==tr("er", "modify - delete (erase)")) {
		ret = RS2::ActionModifyDelete;
	} else if (c==tr("oo", "modify - undo (oops)")) {
		ret = RS2::ActionEditUndo;
	} else if (c==tr("uu", "modify - redo")) {
		ret = RS2::ActionEditRedo;
	} else if (c==tr("xp", "modify - explode") || 
			c==tr("ex", "modify - explode")) {
		ret = RS2::ActionBlocksExplode;
	}

    return ret;
}
コード例 #29
0
/**
 * Checks if the given string 'str' matches the given command 'cmd' for action
 * 'action'.
 *
 * @param cmd The command we want to check for (e.g. 'angle').
 * @param action The action which wants to know.
 * @param str The string typically entered by the user.
 */
bool RS_Commands::checkCommand(const RS_String& cmd, const RS_String& str,
                               RS2::ActionType /*action*/) {

    RS_String strl = str.lower();

    if (cmd=="angle") {
        if (strl==tr("angle") || strl==tr("ang", "angle") ||
                strl==tr("a", "angle")) {
            return true;
        }
    } else if (cmd=="center") {
        if (strl==tr("center") || strl==tr("cen", "center") ||
                strl==tr("c", "center")) {
            return true;
        }
    } else if (cmd=="chord length") {
        if (strl==tr("length", "chord length") ||
                strl==tr("l", "chord length")) {
            return true;
        }
    } else if (cmd=="close") {
        if (strl==tr("close") ||
                strl==tr("c", "close")) {
            return true;
        }
    } else if (cmd=="columns") {
        if (strl==tr("columns") || strl==tr("cols", "columns") ||
                strl==tr("c", "columns")) {
            return true;
        }
    } else if (cmd=="columnspacing") {
        if (strl==tr("columnspacing", "columnspacing for inserts") ||
                strl==tr("colspacing", "columnspacing for inserts") ||
                strl==tr("cs", "columnspacing for inserts")) {
            return true;
        }
    } else if (cmd=="factor") {
        if (strl==tr("factor") || strl==tr("fact", "factor") ||
                strl==tr("f", "factor")) {
            return true;
        }
    } else if (cmd=="help") {
        if (strl==tr("help") || strl==tr("?", "help")) {
            return true;
        }
    } else if (cmd=="length") {
        if (strl==tr("length", "length") ||
                strl==tr("len", "length") ||
                strl==tr("l", "length")) {
            return true;
        }
    } else if (cmd=="length1") {
        if (strl==tr("length1", "length1") ||
                strl==tr("len1", "length1") ||
                strl==tr("l1", "length1")) {
            return true;
        }
    } else if (cmd=="length2") {
        if (strl==tr("length2", "length2") ||
                strl==tr("len2", "length2") ||
                strl==tr("l2", "length2")) {
            return true;
        }
    } else if (cmd=="number") {
        if (strl==tr("number") ||
                strl==tr("num", "number") ||
                strl==tr("n", "number")) {
            return true;
        }
    } else if (cmd=="radius") {
        if (strl==tr("radius") ||
                strl==tr("r", "radius")) {
            return true;
        }
    } else if (cmd=="reversed") {
        if (strl==tr("reversed", "reversed arc") ||
                strl==tr("rev", "reversed arc") ||
                strl==tr("r", "reversed arc")) {
            return true;
        }
    } else if (cmd=="rows") {
        if (strl==tr("rows") || strl==tr("r", "rows")) {
            return true;
        }
    } else if (cmd=="rowspacing") {
        if (strl==tr("rowspacing", "rowspacing for inserts") ||
                strl==tr("rs", "rowspacing for inserts")) {
            return true;
        }
    } else if (cmd=="text") {
        if (strl==tr("text") ||
                strl==tr("t", "text")) {
            return true;
        }
    } else if (cmd=="through") {
        if (strl==tr("through") ||
                strl==tr("t", "through")) {
            return true;
        }
    } else if (cmd=="undo") {
        if (strl==tr("undo") ||
                strl==tr("u", "undo")) {
            return true;
        }
    }

    return false;
}
コード例 #30
0
ファイル: rs_units.cpp プロジェクト: Seablade/vec2web
/**
 * Converts a string to a paper format.
 */
RS2::PaperFormat RS_Units::stringToPaperFormat(const RS_String& p) {
    RS_String ls = p.lower();
    RS2::PaperFormat ret = RS2::Custom;

    if (p=="custom") {
        ret = RS2::Custom;
    } else if (p=="letter") {
        ret = RS2::Letter;
    } else if (p=="legal") {
        ret = RS2::Legal;
    } else if (p=="executive") {
        ret = RS2::Executive;
    } else if (p=="a0") {
        ret = RS2::A0;
    } else if (p=="a1") {
        ret = RS2::A1;
    } else if (p=="a2") {
        ret = RS2::A2;
    } else if (p=="a3") {
        ret = RS2::A3;
    } else if (p=="a4") {
        ret = RS2::A4;
    } else if (p=="a5") {
        ret = RS2::A5;
    } else if (p=="a6") {
        ret = RS2::A6;
    } else if (p=="a7") {
        ret = RS2::A7;
    } else if (p=="a8") {
        ret = RS2::A8;
    } else if (p=="a9") {
        ret = RS2::A9;
    } else if (p=="b0") {
        ret = RS2::B0;
    } else if (p=="b1") {
        ret = RS2::B1;
    } else if (p=="b2") {
        ret = RS2::B2;
    } else if (p=="b3") {
        ret = RS2::B3;
    } else if (p=="b4") {
        ret = RS2::B4;
    } else if (p=="b5") {
        ret = RS2::B5;
    } else if (p=="b6") {
        ret = RS2::B6;
    } else if (p=="b7") {
        ret = RS2::B7;
    } else if (p=="b8") {
        ret = RS2::B8;
    } else if (p=="b9") {
        ret = RS2::B9;
    } else if (p=="b10") {
        ret = RS2::B10;
    }
    /*else if (p=="c0") {
           ret = RS2::C0;
       } else if (p=="c1") {
           ret = RS2::C1;
       } else if (p=="c2") {
           ret = RS2::C2;
       } else if (p=="c3") {
           ret = RS2::C3;
       } else if (p=="c4") {
           ret = RS2::C4;
       } else if (p=="c5") {
           ret = RS2::C5;
       } else if (p=="c6") {
           ret = RS2::C6;
       } else if (p=="c7") {
           ret = RS2::C7;
       } else if (p=="c8") {
           ret = RS2::C8;
       } else if (p=="c9") {
           ret = RS2::C9;
       } else if (p=="c10") {
           ret = RS2::C10;
       }*/
    else if (p=="c5e") {
        ret = RS2::C5E;
    } else if (p=="comm10e") {
        ret = RS2::Comm10E;
    } else if (p=="dle") {
        ret = RS2::DLE;
    } else if (p=="folio") {
        ret = RS2::Folio;
    //} else if (p=="ledger") {
    //    ret = RS2::Ledger;
    } else if (p=="tabloid") {
        ret = RS2::Tabloid;
    } else if (p=="npagesize") {
        ret = RS2::NPageSize;
    }

    return ret;
}