diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/MainWindow.h | 1 | ||||
| -rw-r--r-- | src/PolySetCGALEvaluator.cc | 4 | ||||
| -rw-r--r-- | src/Preferences.cc | 12 | ||||
| -rw-r--r-- | src/Preferences.h | 2 | ||||
| -rw-r--r-- | src/Preferences.ui | 57 | ||||
| -rw-r--r-- | src/calc.cc | 40 | ||||
| -rw-r--r-- | src/calc.h | 8 | ||||
| -rw-r--r-- | src/dxfdata.cc | 8 | ||||
| -rw-r--r-- | src/highlighter.cc | 150 | ||||
| -rw-r--r-- | src/highlighter.h | 3 | ||||
| -rw-r--r-- | src/linearextrude.cc | 4 | ||||
| -rw-r--r-- | src/mainwin.cc | 8 | ||||
| -rw-r--r-- | src/openscad.h | 1 | ||||
| -rw-r--r-- | src/primitives.cc | 18 | 
14 files changed, 242 insertions, 74 deletions
| diff --git a/src/MainWindow.h b/src/MainWindow.h index ac999bf..4948d46 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -70,6 +70,7 @@ private slots:  	void updateTVal();  	void setFileName(const QString &filename);  	void setFont(const QString &family, uint size); +	void setSyntaxHighlight(const QString &s);  	void showProgress();  	void openCSGSettingsChanged(); diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index a2d896d..0b57de1 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -13,10 +13,10 @@  #include "dxfdata.h"  #include "dxftess.h"  #include "module.h" +#include "calc.h"  #include "svg.h"  #include "printutils.h" -#include "openscad.h" // get_fragments_from_r()  #include <boost/foreach.hpp>  #include <vector> @@ -469,7 +469,7 @@ PolySet *PolySetCGALEvaluator::rotateDxfData(const RotateExtrudeNode &node, DxfD  			}  		} -		int fragments = get_fragments_from_r(max_x-min_x, node.fn, node.fs, node.fa); +		int fragments = Calc::get_fragments_from_r(max_x-min_x, node.fn, node.fs, node.fa);  		double ***points;  		points = new double**[fragments]; diff --git a/src/Preferences.cc b/src/Preferences.cc index 591ccf6..b63ca7b 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -63,6 +63,7 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)  	QString found_family(QFontInfo(font).family());  	this->defaultmap["editor/fontfamily"] = found_family;   	this->defaultmap["editor/fontsize"] = 12; +	this->defaultmap["editor/syntaxhighlight"] = "For Light Background";  	uint savedsize = getValue("editor/fontsize").toUInt();  	QFontDatabase db; @@ -280,6 +281,13 @@ void Preferences::on_fontSize_editTextChanged(const QString &size)  	emit fontChanged(getValue("editor/fontfamily").toString(), intsize);  } +void Preferences::on_syntaxHighlight_currentIndexChanged(const QString &s) +{ +	QSettings settings; +	settings.setValue("editor/syntaxhighlight", s); +	emit syntaxHighlightChanged(s); +} +  void unimplemented_msg()  {    QMessageBox mbox; @@ -416,6 +424,10 @@ void Preferences::updateGUI()  		this->fontSize->setEditText(fontsize);  	} +	QString shighlight = getValue("editor/syntaxhighlight").toString(); +	int shidx = this->syntaxHighlight->findText(shighlight); +	if (shidx >= 0) this->syntaxHighlight->setCurrentIndex(shidx); +  	if (AutoUpdater *updater = AutoUpdater::updater()) {  		this->updateCheckBox->setChecked(updater->automaticallyChecksForUpdates());  		this->snapshotCheckBox->setChecked(updater->enableSnapshots()); diff --git a/src/Preferences.h b/src/Preferences.h index ef8835a..d74ada9 100644 --- a/src/Preferences.h +++ b/src/Preferences.h @@ -25,6 +25,7 @@ public slots:  	void on_colorSchemeChooser_itemSelectionChanged();  	void on_fontChooser_activated(const QString &);  	void on_fontSize_editTextChanged(const QString &); +	void on_syntaxHighlight_currentIndexChanged(const QString &);  	void on_openCSGWarningBox_toggled(bool);  	void on_enableOpenCSGBox_toggled(bool);  	void on_cgalCacheSizeEdit_textChanged(const QString &); @@ -39,6 +40,7 @@ signals:  	void requestRedraw() const;  	void fontChanged(const QString &family, uint size) const;  	void openCSGSettingsChanged() const; +	void syntaxHighlightChanged(const QString &s);  private:  	Preferences(QWidget *parent = NULL); diff --git a/src/Preferences.ui b/src/Preferences.ui index 78a1cf6..100bcb1 100644 --- a/src/Preferences.ui +++ b/src/Preferences.ui @@ -27,7 +27,7 @@      <item>       <widget class="QStackedWidget" name="stackedWidget">        <property name="currentIndex"> -       <number>3</number> +       <number>1</number>        </property>        <widget class="QWidget" name="page3DView">         <layout class="QVBoxLayout" name="verticalLayout_4"> @@ -165,6 +165,61 @@           </layout>          </item>          <item> +         <layout class="QHBoxLayout" name="horizontalLayout_5"> +          <property name="bottomMargin"> +           <number>0</number> +          </property> +          <item> +           <widget class="QLabel" name="label_9"> +            <property name="font"> +             <font> +              <weight>75</weight> +              <bold>true</bold> +             </font> +            </property> +            <property name="text"> +             <string>Color syntax highlighting</string> +            </property> +           </widget> +          </item> +          <item> +           <spacer name="horizontalSpacer_3"> +            <property name="orientation"> +             <enum>Qt::Horizontal</enum> +            </property> +            <property name="sizeType"> +             <enum>QSizePolicy::Maximum</enum> +            </property> +            <property name="sizeHint" stdset="0"> +             <size> +              <width>30</width> +              <height>20</height> +             </size> +            </property> +           </spacer> +          </item> +          <item> +           <widget class="QComboBox" name="syntaxHighlight"> +            <item> +             <property name="text"> +              <string>For Light Background</string> +             </property> +            </item> +            <item> +             <property name="text"> +              <string>For Dark Background</string> +             </property> +            </item> +            <item> +             <property name="text"> +              <string>Off</string> +             </property> +            </item> +           </widget> +          </item> +         </layout> +        </item> +        <item>           <spacer name="verticalSpacer_4">            <property name="orientation">             <enum>Qt::Vertical</enum> diff --git a/src/calc.cc b/src/calc.cc new file mode 100644 index 0000000..bdae085 --- /dev/null +++ b/src/calc.cc @@ -0,0 +1,40 @@ +/* + *  OpenSCAD (www.openscad.org) + *  Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + *                          Marius Kintel <marius@kintel.net> + * + *  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. + * + *  As a special exception, you have permission to link this program + *  with the CGAL library and distribute executables, as long as you + *  follow the requirements of the GNU GPL in regard to all of the + *  software in the executable aside from CGAL. + * + *  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 "calc.h" +#include "grid.h" + +/*! +	Returns the number of subdivision of a whole circle, given radius and +	the three special variables $fn, $fs and $fa +*/ +int Calc::get_fragments_from_r(double r, double fn, double fs, double fa) +{ +	if (r < GRID_FINE) return 3; +	if (fn > 0.0) return (int)(fn >= 3 ? fn : 3); +	return (int)ceil(fmax(fmin(360.0 / fa, r*2*M_PI / fs), 5)); +} + diff --git a/src/calc.h b/src/calc.h new file mode 100644 index 0000000..1ac9e17 --- /dev/null +++ b/src/calc.h @@ -0,0 +1,8 @@ +#ifndef CALC_H_ +#define CALC_H_ + +namespace Calc { +	int get_fragments_from_r(double r, double fn, double fs, double fa); +} + +#endif diff --git a/src/dxfdata.cc b/src/dxfdata.cc index 8415228..9b61b93 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -28,7 +28,7 @@  #include "grid.h"  #include "printutils.h"  #include "handle_dep.h" -#include "openscad.h" // get_fragments_from_r() +#include "calc.h"  #include <fstream>  #include "mathc99.h" @@ -189,7 +189,7 @@ DxfData::DxfData(double fn, double fs, double fa,  				}  			}  			else if (mode == "CIRCLE") { -				int n = get_fragments_from_r(radius, fn, fs, fa); +				int n = Calc::get_fragments_from_r(radius, fn, fs, fa);  				Vector2d center(xverts[0], yverts[0]);  				for (int i = 0; i < n; i++) {  					double a1 = (2*M_PI*i)/n; @@ -200,7 +200,7 @@ DxfData::DxfData(double fn, double fs, double fa,  			}  			else if (mode == "ARC") {  				Vector2d center(xverts[0], yverts[0]); -				int n = get_fragments_from_r(radius, fn, fs, fa); +				int n = Calc::get_fragments_from_r(radius, fn, fs, fa);  				while (arc_start_angle > arc_stop_angle)  					arc_stop_angle += 360.0;  				n = (int)ceil(n * (arc_stop_angle-arc_start_angle) / 360); @@ -237,7 +237,7 @@ DxfData::DxfData(double fn, double fs, double fa,  				// the ratio stored in 'radius; due to the parser code not checking entity type  				double r_minor = r_major * radius;  				double sweep_angle = ellipse_stop_angle-ellipse_start_angle; -				int n = get_fragments_from_r(r_major, fn, fs, fa); +				int n = Calc::get_fragments_from_r(r_major, fn, fs, fa);  				n = (int)ceil(n * sweep_angle / (2 * M_PI));  //				Vector2d p1;  				Vector2d p1; p1 << 0,0; diff --git a/src/highlighter.cc b/src/highlighter.cc index 1da0e88..2fb7c65 100644 --- a/src/highlighter.cc +++ b/src/highlighter.cc @@ -121,72 +121,110 @@  */  #include "highlighter.h" +#include "Preferences.h"  #include <QTextDocument>  #include <QTextCursor>  #include <QColor> -//#include <iostream> +//#include "printutils.h" + +void format_colors_for_light_background(QMap<QString,QTextCharFormat> &formats) +{ +	//PRINT("format for light"); +	formats["operator"].setForeground(Qt::blue); +	formats["math"].setForeground(QColor("Green")); +	formats["keyword"].setForeground(QColor("Green")); +	formats["keyword"].setToolTip("Keyword"); +	formats["transform"].setForeground(QColor("Indigo")); +	formats["csgop"].setForeground(QColor("DarkGreen")); +	formats["prim3d"].setForeground(QColor("DarkBlue")); +	formats["prim2d"].setForeground(QColor("MidnightBlue")); +	formats["import"].setForeground(Qt::darkYellow); +	formats["special"].setForeground(Qt::darkGreen); +	formats["extrude"].setForeground(Qt::darkGreen); +	formats["bracket"].setForeground(QColor("Green")); +	formats["curlies"].setForeground(QColor(32,32,20)); +	formats["bool"].setForeground(QColor("DarkRed")); + +	formats["_$quote"].setForeground(Qt::darkMagenta); +	formats["_$comment"].setForeground(Qt::darkCyan); +	formats["_$number"].setForeground(QColor("DarkRed")); +} + +void format_colors_for_dark_background(QMap<QString,QTextCharFormat> &formats) +{ +	//PRINT("format for dark"); +	formats["operator"].setForeground(Qt::blue); +	formats["math"].setForeground(Qt::green); +	formats["keyword"].setForeground(QColor("LightGreen")); +	formats["keyword"].setToolTip("Keyword"); +	formats["transform"].setForeground(QColor("Indigo")); +	formats["csgop"].setForeground(QColor("LightGreen")); +	formats["prim3d"].setForeground(QColor("LightBlue")); +	formats["prim2d"].setForeground(QColor("LightBlue")); +	formats["import"].setForeground(QColor("LightYellow")); +	formats["special"].setForeground(QColor("LightGreen")); +	formats["extrude"].setForeground(QColor("LightGreen")); +	formats["bracket"].setForeground(QColor("Green")); +	formats["curlies"].setForeground(QColor(132,132,120)); +	formats["bool"].setForeground(QColor("LightRed")); + +	formats["_$quote"].setForeground(Qt::magenta); +	formats["_$comment"].setForeground(Qt::cyan); +	formats["_$number"].setForeground(Qt::red); +} + +void Highlighter::assignFormatsToTokens(const QString &s) +{ +	//PRINTB("assign fmts %s",s.toStdString()); +	if (s=="For Light Background") { +		format_colors_for_light_background(this->typeformats); +	} else if (s=="For Dark Background") { +		format_colors_for_dark_background(this->typeformats); +	} else return; + +	// Put each token into single QHash, and map it to it's appropriate +	// qtextchar format (color, bold, etc). For example, '(' is type  +	// 'bracket' so it should get the 'bracket' format from  +	// typeformats[] which is, maybe, Green. + +	QList<QString>::iterator ki; +	QList<QString> toktypes = tokentypes.keys(); +	for ( ki=toktypes.begin(); ki!=toktypes.end(); ++ki ) { +		QString toktype = *ki; +		QStringList::iterator it; +		for ( it = tokentypes[toktype].begin(); it < tokentypes[toktype].end(); ++it) { +			QString token = *it; +			//PRINTB("set format for %s: type %s", token.toStdString()%toktype.toStdString() );; +			tokenFormats[ token ] = typeformats [ toktype ]; +		} +	} +}  Highlighter::Highlighter(QTextDocument *parent)  		: QSyntaxHighlighter(parent)  {  	tokentypes["operator"] << "=" << "!" << "&&" << "||" << "+" << "-" << "*" << "/" << "%" << "!" << "#" << ";"; -	typeformats["operator"].setForeground(Qt::blue); -  	tokentypes["math"] << "abs" << "sign" << "acos" << "asin" << "atan" << "atan2" << "sin" << "cos" << "floor" << "round" << "ceil" << "ln" << "log" << "lookup" << "min" << "max" << "pow" << "sqrt" << "exp" << "rands"; -	typeformats["math"].setForeground(Qt::green); -	  	tokentypes["keyword"] << "module" << "function" << "for" << "intersection_for" << "if" << "assign" << "echo"<< "search" << "str"; -	typeformats["keyword"].setForeground(QColor("Green")); -	typeformats["keyword"].setToolTip("Keyword"); -  	tokentypes["transform"] << "scale" << "translate" << "rotate" << "multmatrix" << "color" << "projection" << "hull" << "resize" << "mirror" << "minkowski"; -	typeformats["transform"].setForeground(QColor("Indigo")); -  	tokentypes["csgop"]	<< "union" << "intersection" << "difference" << "render"; -	typeformats["csgop"].setForeground(QColor("DarkGreen")); -  	tokentypes["prim3d"] << "cube" << "cylinder" << "sphere" << "polyhedron"; -	typeformats["prim3d"].setForeground(QColor("DarkBlue")); -  	tokentypes["prim2d"] << "square" << "polygon" << "circle"; -	typeformats["prim2d"].setForeground(QColor("MidnightBlue")); -  	tokentypes["import"] << "include" << "use" << "import_stl" << "import" << "import_dxf" << "dxf_dim" << "dxf_cross" << "surface"; -	typeformats["import"].setForeground(Qt::darkYellow); -  	tokentypes["special"] << "$children" << "child" << "children" << "$fn" << "$fa" << "$fs" << "$t" << "$vpt" << "$vpr"; -	typeformats["special"].setForeground(Qt::darkGreen); -  	tokentypes["extrude"] << "linear_extrude" << "rotate_extrude"; -	typeformats["extrude"].setForeground(Qt::darkGreen); -  	tokentypes["bracket"] << "[" << "]" << "(" << ")"; -	typeformats["bracket"].setForeground(QColor("Green")); -  	tokentypes["curlies"] << "{" << "}"; -	typeformats["curlies"].setForeground(QColor(32,32,20)); -  	tokentypes["bool"] << "true" << "false"; -	typeformats["bool"].setForeground(QColor("DarkRed")); -	// Put each token into single QHash, mapped to it's format -	QList<QString>::iterator ki; -	QList<QString> toktypes = tokentypes.keys(); -	for ( ki=toktypes.begin(); ki!=toktypes.end(); ++ki ) { -		QString toktype = *ki; -		QStringList::iterator it; -		for ( it = tokentypes[toktype].begin(); it < tokentypes[toktype].end(); ++it) { -			QString token = *it; -			//std::cout << token.toStdString() << "\n"; -			tokenFormats[ token ] = typeformats [ toktype ]; -		} -	} +	tokentypes["_$comment"] << "_$comment"; // bit of a kludge here +	tokentypes["_$quote"] << "_$quote"; +	tokentypes["_$number"] << "_$number"; -	quoteFormat.setForeground(Qt::darkMagenta); -	commentFormat.setForeground(Qt::darkCyan); -	errorFormat.setBackground(Qt::red); -	numberFormat.setForeground(QColor("DarkRed")); +	QString syntaxhighlight = Preferences::inst()->getValue("editor/syntaxhighlight").toString(); +	this->assignFormatsToTokens(syntaxhighlight); +	errorFormat.setBackground(Qt::red);  	errorState = false;  	errorPos = -1;  	lastErrorBlock = parent->begin(); @@ -198,10 +236,10 @@ void Highlighter::highlightError(int error_pos)  	errorPos = error_pos;  	QTextBlock err_block = document()->findBlock( errorPos ); -	//std::cout << "error pos: "  << error_pos << " doc len: " << document()->characterCount() << "\n"; +	//PRINTB( "error pos: %i doc len: %i ", error_pos % document()->characterCount() );  	while (err_block.text().remove(QRegExp("\\s+")).size()==0) { -		//std::cout << "special case - errors at end of file w whitespace\n"; +		//PRINT("special case - errors at end of file w whitespace";  		err_block = err_block.previous();  		errorPos = err_block.position()+err_block.length() - 2;  	} @@ -211,7 +249,7 @@ void Highlighter::highlightError(int error_pos)  	int block_last_pos = err_block.position() + err_block.length() - 1;  	if ( errorPos == block_last_pos ) { -		//std::cout << "special case - errors at ends of certain blocks\n"; +		//PRINT( "special case - errors at ends of certain blocks");  		errorPos--;  	}  	err_block = document()->findBlock(errorPos); @@ -254,6 +292,18 @@ void Highlighter::highlightBlock(const QString &text)  	//  << ", err:" << errorPos << "," << errorState  	//  << ", text:'" << text.toStdString() << "'\n"; +	// If desired, skip all highlighting .. except for error highlighting. +	if (Preferences::inst()->getValue("editor/syntaxhighlight").toString()==QString("Off")) { +		if (errorState) +			setFormat( errorPos - block_first_pos, 1, errorFormat); +		return; +	} + +	// bit of a kludge (for historical convenience) +	QTextCharFormat "eFormat = tokenFormats["_$quote"]; +	QTextCharFormat &commentFormat = tokenFormats["_$comment"]; +	QTextCharFormat &numberFormat = tokenFormats["_$number"]; +  	// Split the block into chunks (tokens), based on whitespace,  	// and then highlight each token as appropriate  	QString newtext = text; @@ -265,7 +315,7 @@ void Highlighter::highlightBlock(const QString &text)  	for ( sh = splitHelpers.begin(); sh!=splitHelpers.end(); ++sh ) {  		newtext = newtext.replace( *sh, " " + *sh + " ");  	} -	//std::cout << "\nnewtext: " << newtext.toStdString() << "\n"; +	//PRINTB("\nnewtext: %s", newtext.toStdString() );  	QStringList tokens = newtext.split(QRegExp("\\s"));  	int tokindex = 0; // tokindex helps w duplicate tokens in a single block  	bool numtest; @@ -273,14 +323,16 @@ void Highlighter::highlightBlock(const QString &text)  		if ( tokenFormats.contains( *token ) ) {  			tokindex = text.indexOf( *token, tokindex );  			setFormat( tokindex, token->size(), tokenFormats[ *token ]); -			//std::cout  << "found tok '" << (*token).toStdString() << "' at " << tokindex << "\n"; +			std::string tokprint = (*token).toStdString(); +			//PRINTB("found tok '%s' at %i", tokprint % tokindex );  			tokindex += token->size();  		} else {  			(*token).toDouble( &numtest );  			if ( numtest ) {  				tokindex = text.indexOf( *token, tokindex );  				setFormat( tokindex, token->size(), numberFormat ); -				//std::cout  << "found num '" << (*token).toStdString() << "' at " << tokindex << "\n"; +				std::string tokprint = (*token).toStdString(); +				//PRINTB("found num '%s' at %i", tokprint % tokindex );  				tokindex += token->size();  			}  		} diff --git a/src/highlighter.h b/src/highlighter.h index b4ffae8..10f9b0a 100644 --- a/src/highlighter.h +++ b/src/highlighter.h @@ -10,11 +10,12 @@ class Highlighter : public QSyntaxHighlighter  public:  	enum state_e {NORMAL=-1,QUOTE,COMMENT};  	QHash<QString, QTextCharFormat> tokenFormats; -	QTextCharFormat errorFormat, commentFormat, quoteFormat, numberFormat; +	QTextCharFormat errorFormat;  	Highlighter(QTextDocument *parent);  	void highlightBlock(const QString &text);  	void highlightError(int error_pos);  	void unhighlightLastError(); +	void assignFormatsToTokens(const QString &);  private:  	QTextBlock lastErrorBlock;  	int errorPos; diff --git a/src/linearextrude.cc b/src/linearextrude.cc index c5d4529..1812504 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -32,7 +32,7 @@  #include "fileutils.h"  #include "builtin.h"  #include "PolySetEvaluator.h" -#include "openscad.h" // get_fragments_from_r() +#include "calc.h"  #include "mathc99.h"   #include <sstream> @@ -113,7 +113,7 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI  		if (slices.type() == Value::NUMBER) {  			node->slices = (int)slices.toDouble();  		} else { -			node->slices = (int)fmax(2, fabs(get_fragments_from_r(node->height, +			node->slices = (int)fmax(2, fabs(Calc::get_fragments_from_r(node->height,  					node->fn, node->fs, node->fa) * node->twist / 360));  		}  		node->has_twist = true; diff --git a/src/mainwin.cc b/src/mainwin.cc index 1ad8bc8..c2a7b7e 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -369,6 +369,8 @@ MainWindow::MainWindow(const QString &filename)  					this, SLOT(setFont(const QString&,uint)));  	connect(Preferences::inst(), SIGNAL(openCSGSettingsChanged()),  					this, SLOT(openCSGSettingsChanged())); +	connect(Preferences::inst(), SIGNAL(syntaxHighlightChanged(const QString&)),  +					this, SLOT(setSyntaxHighlight(const QString&)));  	Preferences::inst()->apply();  	// make sure it looks nice.. @@ -1899,6 +1901,12 @@ void MainWindow::setFont(const QString &family, uint size)  	editor->setFont(font);  } +void MainWindow::setSyntaxHighlight(const QString &s) +{ +	this->highlighter->assignFormatsToTokens( s ); +	this->highlighter->rehighlight(); // slow on large files +} +  void MainWindow::quit()  {  	QCloseEvent ev; diff --git a/src/openscad.h b/src/openscad.h index dd379a9..0d146c1 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -28,7 +28,6 @@  #define OPENSCAD_H  extern class FileModule *parse(const char *text, const char *path, int debug); -extern int get_fragments_from_r(double r, double fn, double fs, double fa);  #include <string>  extern std::string commandline_commands; diff --git a/src/primitives.cc b/src/primitives.cc index f1a4ba7..53b2e19 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -34,6 +34,7 @@  #include "printutils.h"  #include "visitor.h"  #include "context.h" +#include "calc.h"  #include <sstream>  #include <assert.h>  #include <boost/assign/std/vector.hpp> @@ -275,17 +276,6 @@ AbstractNode *PrimitiveModule::instantiate(const Context *ctx, const ModuleInsta  	return node;  } -/*! -	Returns the number of subdivision of a whole circle, given radius and -	the three special variables $fn, $fs and $fa -*/ -int get_fragments_from_r(double r, double fn, double fs, double fa) -{ -	if (r < GRID_FINE) return 3; -	if (fn > 0.0) return (int)(fn >= 3 ? fn : 3); -	return (int)ceil(fmax(fmin(360.0 / fa, r*2*M_PI / fs), 5)); -} -  struct point2d {  	double x, y;  }; @@ -364,7 +354,7 @@ PolySet *PrimitiveNode::evaluate_polyset(class PolySetEvaluator *) const  			double z;  		}; -		int fragments = get_fragments_from_r(r1, fn, fs, fa); +		int fragments = Calc::get_fragments_from_r(r1, fn, fs, fa);  		int rings = (fragments+1)/2;  // Uncomment the following three lines to enable experimental sphere tesselation  //		if (rings % 2 == 0) rings++; // To ensure that the middle ring is at phi == 0 degrees @@ -427,7 +417,7 @@ sphere_next_r2:  	if (this->type == CYLINDER &&   			this->h > 0 && this->r1 >=0 && this->r2 >= 0 && (this->r1 > 0 || this->r2 > 0))  	{ -		int fragments = get_fragments_from_r(fmax(this->r1, this->r2), this->fn, this->fs, this->fa); +		int fragments = Calc::get_fragments_from_r(fmax(this->r1, this->r2), this->fn, this->fs, this->fa);  		double z1, z2;  		if (this->center) { @@ -525,7 +515,7 @@ sphere_next_r2:  	if (this->type == CIRCLE)  	{ -		int fragments = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa); +		int fragments = Calc::get_fragments_from_r(this->r1, this->fn, this->fs, this->fa);  		p->is2d = true;  		p->append_poly(); | 
