Mod/Points/Gui/Command.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <qaction.h>
00027 # include <qdir.h>
00028 # include <qfileinfo.h>
00029 # include <Inventor/events/SoMouseButtonEvent.h>
00030 #endif
00031
00032 #include <Base/Exception.h>
00033 #include <Base/Matrix.h>
00034 #include <App/Document.h>
00035 #include <Gui/Application.h>
00036 #include <Gui/Document.h>
00037 #include <Gui/MainWindow.h>
00038 #include <Gui/Command.h>
00039 #include <Gui/FileDialog.h>
00040 #include <Gui/Selection.h>
00041 #include <Gui/ViewProvider.h>
00042 #include <Gui/View3DInventor.h>
00043 #include <Gui/View3DInventorViewer.h>
00044
00045 #include "../App/PointsFeature.h"
00046 #include "DlgPointsReadImp.h"
00047 #include "ViewProvider.h"
00048
00049
00050
00051
00052
00053
00054
00055 DEF_STD_CMD_A(CmdPointsImport);
00056
00057 CmdPointsImport::CmdPointsImport()
00058 :Command("Points_Import")
00059 {
00060 sAppModule = "Points";
00061 sGroup = QT_TR_NOOP("Points");
00062 sMenuText = QT_TR_NOOP("Import points...");
00063 sToolTipText = QT_TR_NOOP("Imports a point cloud");
00064 sWhatsThis = QT_TR_NOOP("Imports a point cloud");
00065 sStatusTip = QT_TR_NOOP("Imports a point cloud");
00066 sPixmap = "Test1";
00067 }
00068
00069 void CmdPointsImport::activated(int iMsg)
00070 {
00071 QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
00072 QString::null, QString(), QObject::tr("Ascii Points (*.asc);;All Files (*.*)"));
00073 if ( fn.isEmpty() )
00074 return;
00075
00076 if (! fn.isEmpty() )
00077 {
00078 QFileInfo fi;
00079 fi.setFile(fn);
00080
00081 openCommand("Points Import Create");
00082 doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::ImportAscii\",\"%s\")", (const char*)fi.baseName().toAscii());
00083 doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii());
00084 commitCommand();
00085
00086 updateActive();
00087 }
00088 }
00089
00090 bool CmdPointsImport::isActive(void)
00091 {
00092 if( getActiveGuiDocument() )
00093 return true;
00094 else
00095 return false;
00096 }
00097
00098 DEF_STD_CMD_A(CmdPointsExport);
00099
00100 CmdPointsExport::CmdPointsExport()
00101 :Command("Points_Export")
00102 {
00103 sAppModule = "Points";
00104 sGroup = QT_TR_NOOP("Points");
00105 sMenuText = QT_TR_NOOP("Export points...");
00106 sToolTipText = QT_TR_NOOP("Exports a point cloud");
00107 sWhatsThis = QT_TR_NOOP("Exports a point cloud");
00108 sStatusTip = QT_TR_NOOP("Exports a point cloud");
00109 sPixmap = "Test2";
00110 }
00111
00112 void CmdPointsExport::activated(int iMsg)
00113 {
00114 QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
00115 QString::null, QString(), QObject::tr("Ascii Points (*.asc);;All Files (*.*)"));
00116 if ( fn.isEmpty() )
00117 return;
00118
00119 if (! fn.isEmpty() )
00120 {
00121 QFileInfo fi;
00122 fi.setFile(fn);
00123
00124 openCommand("Export Points");
00125 std::vector<App::DocumentObject*> points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId());
00126 doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::Export\",\"%s\")", (const char*)fi.baseName().toAscii());
00127 doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii());
00128 doCommand(Doc,"l=list()");
00129
00130 for ( std::vector<App::DocumentObject*>::const_iterator it = points.begin(); it != points.end(); ++it )
00131 {
00132 doCommand(Doc,"l.append(App.ActiveDocument.getObject(\"%s\"))",(*it)->getNameInDocument());
00133 }
00134
00135 doCommand(Doc,"f.Sources = l");
00136 commitCommand();
00137 updateActive();
00138 }
00139 }
00140
00141 bool CmdPointsExport::isActive(void)
00142 {
00143 return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0;
00144 }
00145
00146 DEF_STD_CMD_A(CmdPointsTransform);
00147
00148 CmdPointsTransform::CmdPointsTransform()
00149 :Command("Points_Transform")
00150 {
00151 sAppModule = "Points";
00152 sGroup = QT_TR_NOOP("Points");
00153 sMenuText = QT_TR_NOOP("Transform Points");
00154 sToolTipText = QT_TR_NOOP("Test to transform a point cloud");
00155 sWhatsThis = QT_TR_NOOP("Test to transform a point cloud");
00156 sStatusTip = QT_TR_NOOP("Test to transform a point cloud");
00157 sPixmap = "Test1";
00158 }
00159
00160 void CmdPointsTransform::activated(int iMsg)
00161 {
00162
00163 Base::Placement trans;
00164 trans.setRotation(Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796));
00165
00166 openCommand("Transform points");
00167
00168
00169
00170
00171
00172
00173 commitCommand();
00174 }
00175
00176 bool CmdPointsTransform::isActive(void)
00177 {
00178 return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0;
00179 }
00180
00181 DEF_STD_CMD_A(CmdPointsPolyCut);
00182
00183 CmdPointsPolyCut::CmdPointsPolyCut()
00184 :Command("Points_PolyCut")
00185 {
00186 sAppModule = "Points";
00187 sGroup = QT_TR_NOOP("Points");
00188 sMenuText = QT_TR_NOOP("Cut point cloud");
00189 sToolTipText = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
00190 sWhatsThis = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
00191 sStatusTip = QT_TR_NOOP("Cuts a point cloud with a picked polygon");
00192 sPixmap = "PolygonPick";
00193 }
00194
00195 void CmdPointsPolyCut::activated(int iMsg)
00196 {
00197 std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId());
00198 for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
00199 if (it == docObj.begin()) {
00200 Gui::Document* doc = getActiveGuiDocument();
00201 Gui::MDIView* view = doc->getActiveView();
00202 if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00203 Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
00204 viewer->setEditing(true);
00205 viewer->startSelection(Gui::View3DInventorViewer::Lasso);
00206 viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), PointsGui::ViewProviderPoints::clipPointsCallback);
00207 }
00208 else {
00209 return;
00210 }
00211 }
00212
00213 Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider( *it );
00214 pVP->startEditing();
00215 }
00216 }
00217
00218 bool CmdPointsPolyCut::isActive(void)
00219 {
00220
00221 return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0;
00222 }
00223
00224 void CreatePointsCommands(void)
00225 {
00226 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00227 rcCmdMgr.addCommand(new CmdPointsImport());
00228 rcCmdMgr.addCommand(new CmdPointsExport());
00229 rcCmdMgr.addCommand(new CmdPointsTransform());
00230 rcCmdMgr.addCommand(new CmdPointsPolyCut());
00231 }