Mod/Drawing/Gui/TaskDialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #ifndef _PreComp_
00027 #endif
00028 
00029 
00030 #include <Standard_math.hxx>
00031 #include "TaskDialog.h"
00032 #include <Gui/Application.h>
00033 #include <Gui/Command.h>
00034 #include <Gui/Selection.h>
00035 #include <Gui/Document.h>
00036 #include <Gui/View3DInventor.h>
00037 #include <Gui/View3DInventorViewer.h>
00038 #include <Mod/Part/App/PartFeature.h>
00039 
00040 using namespace DrawingGui;
00041 
00042 
00043 /* TRANSLATOR DrawingGui::TaskProjection */
00044 
00045 TaskProjection::TaskProjection()
00046 {
00047     QString texts[10] = 
00048     {
00049         tr("Visible sharp edges"),
00050         tr("Visible smooth edges"),
00051         tr("Visible sewn edges"),
00052         tr("Visible outline edges"),
00053         tr("Visible isoparameters"),
00054         tr("Hidden sharp edges"),
00055         tr("Hidden smooth edges"),
00056         tr("Hidden sewn edges"),
00057         tr("Hidden outline edges"),
00058         tr("Hidden isoparameters")
00059     };
00060     widget = new QWidget();
00061     QVBoxLayout *mainLayout = new QVBoxLayout;
00062 
00063     for (int i=0; i<10; i++) {
00064         QCheckBox* cb = new QCheckBox();
00065         if (i < 5)
00066             cb->setChecked(true);
00067         cb->setText(texts[i]);
00068         mainLayout->addWidget(cb);
00069         boxes.push_back(cb);
00070     }
00071 
00072     widget->setLayout(mainLayout);
00073 
00074     taskbox = new Gui::TaskView::TaskBox(
00075         QPixmap(), tr("Project shapes"), false, 0);
00076     taskbox->groupLayout()->addWidget(widget);
00077     Content.push_back(taskbox);
00078 }
00079 
00080 TaskProjection::~TaskProjection()
00081 {
00082     // automatically deleted in the sub-class
00083 }
00084 
00085 bool TaskProjection::accept()
00086 {
00087     Gui::Document* document = Gui::Application::Instance->activeDocument();
00088     if (!document)
00089         return false;
00090     Gui::MDIView* mdi = document->getActiveView();
00091     if (!mdi || !mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId()))
00092         return false;
00093 
00094     Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(mdi)->getViewer();
00095     SbVec3f pnt, dir;
00096     viewer->getNearPlane(pnt, dir);
00097     float x=0, y=1,z=1;
00098     dir.getValue(x,y,z);
00099 
00100     std::vector<Part::Feature*> shapes = Gui::Selection().getObjectsOfType<Part::Feature>();
00101     Gui::Command::openCommand("Project shape");
00102     Gui::Command::doCommand(Gui::Command::Doc,"import Drawing");
00103     for (std::vector<Part::Feature*>::iterator it = shapes.begin(); it != shapes.end(); ++it) {
00104         const char* object = (*it)->getNameInDocument();
00105         Gui::Command::doCommand(Gui::Command::Doc,
00106             "FreeCAD.ActiveDocument.addObject('Drawing::FeatureProjection','%s_proj')", object);
00107         Gui::Command::doCommand(Gui::Command::Doc,
00108             "FreeCAD.ActiveDocument.ActiveObject.Direction=FreeCAD.Vector(%f,%f,%f)", x,y,z);
00109         Gui::Command::doCommand(Gui::Command::Doc,
00110             "FreeCAD.ActiveDocument.ActiveObject.Source=FreeCAD.ActiveDocument.%s", object);
00111         Gui::Command::doCommand(Gui::Command::Doc,
00112             "FreeCAD.ActiveDocument.ActiveObject.VCompound=%s", (boxes[0]->isChecked() ? "True" : "False"));
00113         Gui::Command::doCommand(Gui::Command::Doc,
00114             "FreeCAD.ActiveDocument.ActiveObject.Rg1LineVCompound=%s", (boxes[1]->isChecked() ? "True" : "False"));
00115         Gui::Command::doCommand(Gui::Command::Doc,
00116             "FreeCAD.ActiveDocument.ActiveObject.RgNLineVCompound=%s", (boxes[2]->isChecked() ? "True" : "False"));
00117         Gui::Command::doCommand(Gui::Command::Doc,
00118             "FreeCAD.ActiveDocument.ActiveObject.OutLineVCompound=%s", (boxes[3]->isChecked() ? "True" : "False"));
00119         Gui::Command::doCommand(Gui::Command::Doc,
00120             "FreeCAD.ActiveDocument.ActiveObject.IsoLineVCompound=%s", (boxes[4]->isChecked() ? "True" : "False"));
00121         Gui::Command::doCommand(Gui::Command::Doc,
00122             "FreeCAD.ActiveDocument.ActiveObject.HCompound=%s", (boxes[5]->isChecked() ? "True" : "False"));
00123         Gui::Command::doCommand(Gui::Command::Doc,
00124             "FreeCAD.ActiveDocument.ActiveObject.Rg1LineHCompound=%s", (boxes[6]->isChecked() ? "True" : "False"));
00125         Gui::Command::doCommand(Gui::Command::Doc,
00126             "FreeCAD.ActiveDocument.ActiveObject.RgNLineHCompound=%s", (boxes[7]->isChecked() ? "True" : "False"));
00127         Gui::Command::doCommand(Gui::Command::Doc,
00128             "FreeCAD.ActiveDocument.ActiveObject.OutLineHCompound=%s", (boxes[8]->isChecked() ? "True" : "False"));
00129         Gui::Command::doCommand(Gui::Command::Doc,
00130             "FreeCAD.ActiveDocument.ActiveObject.IsoLineHCompound=%s", (boxes[9]->isChecked() ? "True" : "False"));
00131     }
00132     Gui::Command::updateActive();
00133     Gui::Command::commitCommand();
00134     return true;
00135 }
00136 
00137 #include "moc_TaskDialog.cpp"

Generated on Wed Nov 23 19:00:42 2011 for FreeCAD by  doxygen 1.6.1