Merge branch 'master' of github.com:openscad/openscad

stl_dim
Marius Kintel 2011-07-05 22:37:02 +02:00
commit 31a075a107
4 changed files with 272 additions and 6 deletions

View File

@ -79,6 +79,7 @@ private:
static void consoleOutput(const QString &msg, void *userdata) {
static_cast<MainWindow*>(userdata)->console->append(msg);
}
void loadViewSettings();
private slots:
void actionNew();

View File

@ -118,6 +118,37 @@ static char copyrighttext[] =
"the Free Software Foundation; either version 2 of the License, or"
"(at your option) any later version.";
static void
settings_setValueList(const QString &key,const QList<int> &list)
{
QSettings settings;
settings.beginWriteArray(key);
for (int i=0;i<list.size(); ++i) {
settings.setArrayIndex(i);
settings.setValue("entry",list[i]);
}
settings.endArray();
}
QList<int>
settings_valueList(const QString &key, const QList<int> &defaultList = QList<int>())
{
QSettings settings;
QList<int> result;
if (settings.contains(key+"/size")){
int length = settings.beginReadArray(key);
for (int i = 0; i < length; ++i) {
settings.setArrayIndex(i);
result += settings.value("entry").toInt();
}
settings.endArray();
return result;
} else {
return defaultList;
}
}
MainWindow::MainWindow(const QString &filename)
{
setupUi(this);
@ -335,27 +366,60 @@ MainWindow::MainWindow(const QString &filename)
this, SLOT(setFont(const QString&,uint)));
Preferences::inst()->apply();
// make sure it looks nice..
QSettings settings;
resize(settings.value("window/size", QSize(800, 600)).toSize());
move(settings.value("window/position", QPoint(0, 0)).toPoint());
QList<int> s1sizes = settings_valueList("window/splitter1sizes",QList<int>()<<400<<400);
QList<int> s2sizes = settings_valueList("window/splitter2sizes",QList<int>()<<400<<200);
splitter1->setSizes(s1sizes);
splitter2->setSizes(s2sizes);
// display this window and check for OpenGL 2.0 (OpenCSG) support
viewModeThrownTogether();
show();
// make sure it looks nice..
resize(800, 600);
splitter1->setSizes(QList<int>() << 400 << 400);
splitter2->setSizes(QList<int>() << 400 << 200);
#ifdef ENABLE_OPENCSG
viewModeOpenCSG();
#else
viewModeThrownTogether();
#endif
viewPerspective();
loadViewSettings();
setAcceptDrops(true);
clearCurrentOutput();
}
void
MainWindow::loadViewSettings(){
QSettings settings;
if (settings.value("view/showEdges").toBool()) {
viewActionShowEdges->setChecked(true);
viewModeShowEdges();
}
if (settings.value("view/showAxes").toBool()) {
viewActionShowAxes->setChecked(true);
viewModeShowAxes();
}
if (settings.value("view/showCrosshairs").toBool()) {
viewActionShowCrosshairs->setChecked(true);
viewModeShowCrosshairs();
}
if (settings.value("view/orthogonalProjection").toBool()) {
viewOrthogonal();
} else {
viewPerspective();
}
if (settings.value("view/hideConsole").toBool()) {
viewActionHide->setChecked(true);
hideConsole();
}
if (settings.value("view/hideEditor").toBool()) {
editActionHide->setChecked(true);
hideEditor();
}
}
MainWindow::~MainWindow()
{
if (root_module)
@ -952,10 +1016,13 @@ void MainWindow::actionReload()
void MainWindow::hideEditor()
{
QSettings settings;
if (editActionHide->isChecked()) {
editor->hide();
settings.setValue("view/hideEditor",true);
} else {
editor->show();
settings.setValue("view/hideEditor",false);
}
}
@ -1656,17 +1723,23 @@ void MainWindow::viewModeThrownTogether()
void MainWindow::viewModeShowEdges()
{
QSettings settings;
settings.setValue("view/showEdges",viewActionShowEdges->isChecked());
screen->updateGL();
}
void MainWindow::viewModeShowAxes()
{
QSettings settings;
settings.setValue("view/showAxes",viewActionShowAxes->isChecked());
screen->setShowAxes(viewActionShowAxes->isChecked());
screen->updateGL();
}
void MainWindow::viewModeShowCrosshairs()
{
QSettings settings;
settings.setValue("view/showCrosshairs",viewActionShowCrosshairs->isChecked());
screen->setShowCrosshairs(viewActionShowCrosshairs->isChecked());
screen->updateGL();
}
@ -1770,6 +1843,8 @@ void MainWindow::viewCenter()
void MainWindow::viewPerspective()
{
QSettings settings;
settings.setValue("view/orthogonalProjection",false);
viewActionPerspective->setChecked(true);
viewActionOrthogonal->setChecked(false);
screen->setOrthoMode(false);
@ -1778,6 +1853,8 @@ void MainWindow::viewPerspective()
void MainWindow::viewOrthogonal()
{
QSettings settings;
settings.setValue("view/orthogonalProjection",true);
viewActionPerspective->setChecked(false);
viewActionOrthogonal->setChecked(true);
screen->setOrthoMode(true);
@ -1786,10 +1863,13 @@ void MainWindow::viewOrthogonal()
void MainWindow::hideConsole()
{
QSettings settings;
if (viewActionHide->isChecked()) {
console->hide();
settings.setValue("view/hideConsole",true);
} else {
console->show();
settings.setValue("view/hideConsole",false);
}
}
@ -1856,6 +1936,11 @@ MainWindow::maybeSave()
void MainWindow::closeEvent(QCloseEvent *event)
{
if (maybeSave()) {
QSettings settings;
settings.setValue("window/size", size());
settings.setValue("window/position", pos());
settings_setValueList("window/splitter1sizes",splitter1->sizes());
settings_setValueList("window/splitter2sizes",splitter2->sizes());
event->accept();
} else {
event->ignore();

View File

@ -227,6 +227,27 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
if (v.type == Value::VECTOR) {
for (int i = 0; i < 4; i++)
node->m[16+i] = i < v.vec.size() ? v.vec[i]->num : 1.0;
} else if (v.type == Value::STRING) {
double alpha = 1.0;
QString colorname = v.text;
if (v.text.contains(",")) {
QStringList chunks = v.text.split(",");
colorname = chunks[0];
bool parseok;
alpha = chunks[1].toDouble(&parseok);
if (!parseok) alpha=1.0;
}
QColor color;
color.setNamedColor(colorname);
if (color.isValid()) {
node->m[16+0] = color.redF();
node->m[16+1] = color.greenF();
node->m[16+2] = color.blueF();
node->m[16+3] = alpha;
} else {
PRINTF_NOCACHE("WARNING: Color name \"%s\" unknown. Please see",v.text.toUtf8().data());
PRINTF_NOCACHE("WARNING: http://en.wikipedia.org/wiki/Web_colors");
}
}
}

159
testdata/scad/testcolornames.scad vendored Normal file
View File

@ -0,0 +1,159 @@
/* color samples for SVG named colors, for OpenSCAD
Please see http://en.wikipedia.org/wiki/Web_colors
and http://www.w3.org/TR/SVG/types.html#ColorKeywords
for more information. */
$fn=5;
radius=0.8;
//translate([0,0]) color("Red colors") sphere(radius);
translate([1,0]) color("IndianRed") sphere(radius);
translate([2,0]) color("LightCoral") sphere(radius);
translate([3,0]) color("Salmon") sphere(radius);
translate([4,0]) color("DarkSalmon") sphere(radius);
translate([5,0]) color("LightSalmon") sphere(radius);
translate([6,0]) color("Red") sphere(radius);
translate([7,0]) color("Crimson") sphere(radius);
translate([8,0]) color("FireBrick") sphere(radius);
translate([9,0]) color("DarkRed") sphere(radius);
//translate([10,0]) color("Pink colors") sphere(radius);
translate([0,1]) color("Pink") sphere(radius);
translate([1,1]) color("LightPink") sphere(radius);
translate([2,1]) color("HotPink") sphere(radius);
translate([3,1]) color("DeepPink") sphere(radius);
translate([4,1]) color("MediumVioletRed") sphere(radius);
translate([5,1]) color("PaleVioletRed") sphere(radius);
//translate([6,1]) color("Orange colors") sphere(radius);
translate([7,1]) color("LightSalmon") sphere(radius);
translate([8,1]) color("Coral") sphere(radius);
translate([9,1]) color("Tomato") sphere(radius);
translate([10,1]) color("OrangeRed") sphere(radius);
translate([0,2]) color("DarkOrange") sphere(radius);
translate([1,2]) color("Orange") sphere(radius);
//translate([2,2]) color("Yellow colors") sphere(radius);
translate([3,2]) color("Gold") sphere(radius);
translate([4,2]) color("Yellow") sphere(radius);
translate([5,2]) color("LightYellow") sphere(radius);
translate([6,2]) color("LemonChiffon") sphere(radius);
translate([7,2]) color("LightGoldenrodYellow") sphere(radius);
translate([8,2]) color("PapayaWhip") sphere(radius);
translate([9,2]) color("Moccasin") sphere(radius);
translate([10,2]) color("PeachPuff") sphere(radius);
translate([0,3]) color("PaleGoldenrod") sphere(radius);
translate([1,3]) color("Khaki") sphere(radius);
translate([2,3]) color("DarkKhaki") sphere(radius);
//translate([3,3]) color("Purple colors") sphere(radius);
translate([4,3]) color("Lavender") sphere(radius);
translate([5,3]) color("Thistle") sphere(radius);
translate([6,3]) color("Plum") sphere(radius);
translate([7,3]) color("Violet") sphere(radius);
translate([8,3]) color("Orchid") sphere(radius);
translate([9,3]) color("Fuchsia") sphere(radius);
translate([10,3]) color("Magenta") sphere(radius);
translate([0,4]) color("MediumOrchid") sphere(radius);
translate([1,4]) color("MediumPurple") sphere(radius);
translate([2,4]) color("BlueViolet") sphere(radius);
translate([3,4]) color("DarkViolet") sphere(radius);
translate([4,4]) color("DarkOrchid") sphere(radius);
translate([5,4]) color("DarkMagenta") sphere(radius);
translate([6,4]) color("Purple") sphere(radius);
translate([7,4]) color("Indigo") sphere(radius);
translate([8,4]) color("DarkSlateBlue") sphere(radius);
translate([9,4]) color("SlateBlue") sphere(radius);
translate([10,4]) color("MediumSlateBlue") sphere(radius);
//translate([0,5]) color("Green colors") sphere(radius);
translate([1,5]) color("GreenYellow") sphere(radius);
translate([2,5]) color("Chartreuse") sphere(radius);
translate([3,5]) color("LawnGreen") sphere(radius);
translate([4,5]) color("Lime") sphere(radius);
translate([5,5]) color("LimeGreen") sphere(radius);
translate([6,5]) color("PaleGreen") sphere(radius);
translate([7,5]) color("LightGreen") sphere(radius);
translate([8,5]) color("MediumSpringGreen") sphere(radius);
translate([9,5]) color("SpringGreen") sphere(radius);
translate([10,5]) color("MediumSeaGreen") sphere(radius);
translate([0,6]) color("SeaGreen") sphere(radius);
translate([1,6]) color("ForestGreen") sphere(radius);
translate([2,6]) color("Green") sphere(radius);
translate([3,6]) color("DarkGreen") sphere(radius);
translate([4,6]) color("YellowGreen") sphere(radius);
translate([5,6]) color("OliveDrab") sphere(radius);
translate([6,6]) color("Olive") sphere(radius);
translate([7,6]) color("DarkOliveGreen") sphere(radius);
translate([8,6]) color("MediumAquamarine") sphere(radius);
translate([9,6]) color("DarkSeaGreen") sphere(radius);
translate([10,6]) color("LightSeaGreen") sphere(radius);
translate([0,7]) color("DarkCyan") sphere(radius);
translate([1,7]) color("Teal") sphere(radius);
//translate([2,7]) color("Blue/Cyan colors") sphere(radius);
translate([3,7]) color("Aqua") sphere(radius);
translate([4,7]) color("Cyan") sphere(radius);
translate([5,7]) color("LightCyan") sphere(radius);
translate([6,7]) color("PaleTurquoise") sphere(radius);
translate([7,7]) color("Aquamarine") sphere(radius);
translate([8,7]) color("Turquoise") sphere(radius);
translate([9,7]) color("MediumTurquoise") sphere(radius);
translate([10,7]) color("DarkTurquoise") sphere(radius);
translate([0,8]) color("CadetBlue") sphere(radius);
translate([1,8]) color("SteelBlue") sphere(radius);
translate([2,8]) color("LightSteelBlue") sphere(radius);
translate([3,8]) color("PowderBlue") sphere(radius);
translate([4,8]) color("LightBlue") sphere(radius);
translate([5,8]) color("SkyBlue") sphere(radius);
translate([6,8]) color("LightSkyBlue") sphere(radius);
translate([7,8]) color("DeepSkyBlue") sphere(radius);
translate([8,8]) color("DodgerBlue") sphere(radius);
translate([9,8]) color("CornflowerBlue") sphere(radius);
translate([10,8]) color("RoyalBlue") sphere(radius);
translate([0,9]) color("Blue") sphere(radius);
translate([1,9]) color("MediumBlue") sphere(radius);
translate([2,9]) color("DarkBlue") sphere(radius);
translate([3,9]) color("Navy") sphere(radius);
translate([4,9]) color("MidnightBlue") sphere(radius);
//translate([5,9]) color("Brown colors") sphere(radius);
translate([6,9]) color("Cornsilk") sphere(radius);
translate([7,9]) color("BlanchedAlmond") sphere(radius);
translate([8,9]) color("Bisque") sphere(radius);
translate([9,9]) color("NavajoWhite") sphere(radius);
translate([10,9]) color("Wheat") sphere(radius);
translate([0,10]) color("BurlyWood") sphere(radius);
translate([1,10]) color("Tan") sphere(radius);
translate([2,10]) color("RosyBrown") sphere(radius);
translate([3,10]) color("SandyBrown") sphere(radius);
translate([4,10]) color("Goldenrod") sphere(radius);
translate([5,10]) color("DarkGoldenrod") sphere(radius);
translate([6,10]) color("Peru") sphere(radius);
translate([7,10]) color("Chocolate") sphere(radius);
translate([8,10]) color("SaddleBrown") sphere(radius);
translate([9,10]) color("Sienna") sphere(radius);
translate([10,10]) color("Brown") sphere(radius);
translate([0,11]) color("Maroon") sphere(radius);
//translate([1,11]) color("White colors") sphere(radius);
translate([2,11]) color("White") sphere(radius);
translate([3,11]) color("Snow") sphere(radius);
translate([4,11]) color("Honeydew") sphere(radius);
translate([5,11]) color("MintCream") sphere(radius);
translate([6,11]) color("Azure") sphere(radius);
translate([7,11]) color("AliceBlue") sphere(radius);
translate([8,11]) color("GhostWhite") sphere(radius);
translate([9,11]) color("WhiteSmoke") sphere(radius);
translate([10,11]) color("Seashell") sphere(radius);
translate([0,12]) color("Beige") sphere(radius);
translate([1,12]) color("OldLace") sphere(radius);
translate([2,12]) color("FloralWhite") sphere(radius);
translate([3,12]) color("Ivory") sphere(radius);
translate([4,12]) color("AntiqueWhite") sphere(radius);
translate([5,12]) color("Linen") sphere(radius);
translate([6,12]) color("LavenderBlush") sphere(radius);
translate([7,12]) color("MistyRose") sphere(radius);
//translate([8,12]) color("Gray colors") sphere(radius);
translate([9,12]) color("Gainsboro") sphere(radius);
translate([10,12]) color("LightGrey") sphere(radius);
translate([0,13]) color("Silver") sphere(radius);
translate([1,13]) color("DarkGray") sphere(radius);
translate([2,13]) color("Gray") sphere(radius);
translate([3,13]) color("DimGray") sphere(radius);
translate([4,13]) color("LightSlateGray") sphere(radius);
translate([5,13]) color("SlateGray") sphere(radius);
translate([6,13]) color("DarkSlateGray") sphere(radius);
translate([7,13]) color("Black") sphere(radius);