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
00026 #ifndef _PreComp_
00027 # include <qfileinfo.h>
00028 # include <qsplitter.h>
00029 # include <Inventor/nodes/SoOrthographicCamera.h>
00030 # include <Inventor/nodes/SoPerspectiveCamera.h>
00031 # include <Inventor/nodes/SoDirectionalLight.h>
00032 #endif
00033
00034 #include "SplitView3DInventor.h"
00035 #include "View3DInventorViewer.h"
00036 #include "SoFCSelectionAction.h"
00037 #include "Document.h"
00038 #include "Application.h"
00039 #include "NavigationStyle.h"
00040
00041
00042 using namespace Gui;
00043
00044 SplitView3DInventor::SplitView3DInventor( int views, Gui::Document* pcDocument, QWidget* parent, Qt::WFlags wflags )
00045 : MDIView( pcDocument,parent, wflags)
00046 {
00047
00048 setMouseTracking(true);
00049
00050
00051 hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
00052 hGrp->Attach(this);
00053
00054 QSplitter* mainSplitter=0;
00055
00056 if (views <= 3) {
00057 mainSplitter = new QSplitter(Qt::Horizontal, this);
00058 _viewer.push_back(new View3DInventorViewer(mainSplitter));
00059 _viewer.push_back(new View3DInventorViewer(mainSplitter));
00060 if (views==3)
00061 _viewer.push_back(new View3DInventorViewer(mainSplitter));
00062 }
00063 else {
00064 mainSplitter = new QSplitter(Qt::Vertical, this);
00065 QSplitter *topSplitter = new QSplitter(Qt::Horizontal, mainSplitter);
00066 QSplitter *botSplitter = new QSplitter(Qt::Horizontal, mainSplitter);
00067 _viewer.push_back(new View3DInventorViewer(topSplitter));
00068 _viewer.push_back(new View3DInventorViewer(topSplitter));
00069 for (int i=2;i<views;i++)
00070 _viewer.push_back(new View3DInventorViewer(botSplitter));
00071 topSplitter->setOpaqueResize( true );
00072 botSplitter->setOpaqueResize( true );
00073 }
00074
00075 mainSplitter->show();
00076 setCentralWidget(mainSplitter);
00077
00078
00079 OnChange(*hGrp,"EyeDistance");
00080 OnChange(*hGrp,"CornerCoordSystem");
00081 OnChange(*hGrp,"UseAutoRotation");
00082 OnChange(*hGrp,"Gradient");
00083 OnChange(*hGrp,"BackgroundColor");
00084 OnChange(*hGrp,"BackgroundColor2");
00085 OnChange(*hGrp,"BackgroundColor3");
00086 OnChange(*hGrp,"BackgroundColor4");
00087 OnChange(*hGrp,"UseBackgroundColorMid");
00088 OnChange(*hGrp,"UseAntialiasing");
00089 OnChange(*hGrp,"ShowFPS");
00090 OnChange(*hGrp,"Orthographic");
00091 OnChange(*hGrp,"HeadlightColor");
00092 OnChange(*hGrp,"HeadlightDirection");
00093 OnChange(*hGrp,"HeadlightIntensity");
00094 OnChange(*hGrp,"EnableBacklight");
00095 OnChange(*hGrp,"BacklightColor");
00096 OnChange(*hGrp,"BacklightDirection");
00097 OnChange(*hGrp,"BacklightIntensity");
00098 OnChange(*hGrp,"NavigationStyle");
00099 }
00100
00101 SplitView3DInventor::~SplitView3DInventor()
00102 {
00103 hGrp->Detach(this);
00104 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00105 delete *it;
00106 }
00107 }
00108
00109 View3DInventorViewer* SplitView3DInventor::getViewer(unsigned int n) const
00110 {
00111 return (_viewer.size() > n ? _viewer[n] : 0);
00112 }
00113
00115 void SplitView3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason)
00116 {
00117 const ParameterGrp& rGrp = static_cast<ParameterGrp&>(rCaller);
00118 if (strcmp(Reason,"HeadlightColor") == 0) {
00119 unsigned long headlight = rGrp.GetUnsigned("HeadlightColor",ULONG_MAX);
00120 float transparency;
00121 SbColor headlightColor;
00122 headlightColor.setPackedValue((uint32_t)headlight, transparency);
00123 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00124 (*it)->getHeadlight()->color.setValue(headlightColor);
00125 }
00126 else if (strcmp(Reason,"HeadlightDirection") == 0) {
00127 std::string pos = rGrp.GetASCII("HeadlightDirection");
00128 QString flt = QString::fromAscii("([-+]?[0-9]+\\.?[0-9]+)");
00129 QRegExp rx(QString::fromAscii("^\\(%1,%1,%1\\)$").arg(flt));
00130 if (rx.indexIn(QLatin1String(pos.c_str())) > -1) {
00131 float x = rx.cap(1).toFloat();
00132 float y = rx.cap(2).toFloat();
00133 float z = rx.cap(3).toFloat();
00134 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00135 (*it)->getHeadlight()->direction.setValue(x,y,z);
00136 }
00137 }
00138 else if (strcmp(Reason,"HeadlightIntensity") == 0) {
00139 long value = rGrp.GetInt("HeadlightIntensity", 100);
00140 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00141 (*it)->getHeadlight()->intensity.setValue((float)value/100.0f);
00142 }
00143 else if (strcmp(Reason,"EnableBacklight") == 0) {
00144 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00145 (*it)->setBacklight(rGrp.GetBool("EnableBacklight", false));
00146 }
00147 else if (strcmp(Reason,"BacklightColor") == 0) {
00148 unsigned long backlight = rGrp.GetUnsigned("BacklightColor",ULONG_MAX);
00149 float transparency;
00150 SbColor backlightColor;
00151 backlightColor.setPackedValue((uint32_t)backlight, transparency);
00152 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00153 (*it)->getBacklight()->color.setValue(backlightColor);
00154 }
00155 else if (strcmp(Reason,"BacklightDirection") == 0) {
00156 std::string pos = rGrp.GetASCII("BacklightDirection");
00157 QString flt = QString::fromAscii("([-+]?[0-9]+\\.?[0-9]+)");
00158 QRegExp rx(QString::fromAscii("^\\(%1,%1,%1\\)$").arg(flt));
00159 if (rx.indexIn(QLatin1String(pos.c_str())) > -1) {
00160 float x = rx.cap(1).toFloat();
00161 float y = rx.cap(2).toFloat();
00162 float z = rx.cap(3).toFloat();
00163 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00164 (*it)->getBacklight()->direction.setValue(x,y,z);
00165 }
00166 }
00167 else if (strcmp(Reason,"BacklightIntensity") == 0) {
00168 long value = rGrp.GetInt("BacklightIntensity", 100);
00169 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00170 (*it)->getBacklight()->intensity.setValue((float)value/100.0f);
00171 }
00172 else if (strcmp(Reason,"EnablePreselection") == 0) {
00173 SoFCEnableHighlightAction cAct(rGrp.GetBool("EnablePreselection", true));
00174 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00175 cAct.apply((*it)->getSceneGraph());
00176 }
00177 else if (strcmp(Reason,"EnableSelection") == 0) {
00178 SoFCEnableSelectionAction cAct(rGrp.GetBool("EnableSelection", true));
00179 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00180 cAct.apply((*it)->getSceneGraph());
00181 }
00182 else if (strcmp(Reason,"HighlightColor") == 0) {
00183 float transparency;
00184 SbColor highlightColor(0.8f, 0.1f, 0.1f);
00185 unsigned long highlight = (unsigned long)(highlightColor.getPackedValue());
00186 highlight = rGrp.GetUnsigned("HighlightColor", highlight);
00187 highlightColor.setPackedValue((uint32_t)highlight, transparency);
00188 SoSFColor col; col.setValue(highlightColor);
00189 SoFCHighlightColorAction cAct(col);
00190 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00191 cAct.apply((*it)->getSceneGraph());
00192 }
00193 else if (strcmp(Reason,"SelectionColor") == 0) {
00194 float transparency;
00195 SbColor selectionColor(0.1f, 0.8f, 0.1f);
00196 unsigned long selection = (unsigned long)(selectionColor.getPackedValue());
00197 selection = rGrp.GetUnsigned("SelectionColor", selection);
00198 selectionColor.setPackedValue((uint32_t)selection, transparency);
00199 SoSFColor col; col.setValue(selectionColor);
00200 SoFCSelectionColorAction cAct(col);
00201 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00202 cAct.apply((*it)->getSceneGraph());
00203 }
00204 else if (strcmp(Reason,"NavigationStyle") == 0) {
00205
00206
00207
00208
00209
00210
00211 }
00212 else if (strcmp(Reason,"EyeDistance") == 0) {
00213 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00214 (*it)->setStereoOffset(rGrp.GetFloat("EyeDistance",65.0));
00215 }
00216 else if (strcmp(Reason,"CornerCoordSystem") == 0) {
00217 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00218 (*it)->setFeedbackVisibility(rGrp.GetBool("CornerCoordSystem",true));
00219 }
00220 else if (strcmp(Reason,"UseAutoRotation") == 0) {
00221 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00222 (*it)->setAnimationEnabled(rGrp.GetBool("UseAutoRotation",true));
00223 }
00224 else if (strcmp(Reason,"Gradient") == 0) {
00225 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00226 (*it)->setGradientBackgroud((rGrp.GetBool("Gradient",true)));
00227 }
00228 else if (strcmp(Reason,"UseAntialiasing") == 0) {
00229 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00230 (*it)->getGLRenderAction()->setSmoothing(rGrp.GetBool("UseAntialiasing",false));
00231 }
00232 else if (strcmp(Reason,"ShowFPS") == 0) {
00233 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00234 (*it)->setEnabledFPSCounter(rGrp.GetBool("ShowFPS",false));
00235 }
00236 else if (strcmp(Reason,"Orthographic") == 0) {
00237
00238 if (rGrp.GetBool("Orthographic", true)) {
00239 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00240 (*it)->setCameraType(SoOrthographicCamera::getClassTypeId());
00241 }
00242 else {
00243 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00244 (*it)->setCameraType(SoPerspectiveCamera::getClassTypeId());
00245 }
00246 }
00247 else {
00248 unsigned long col1 = rGrp.GetUnsigned("BackgroundColor",3940932863UL);
00249 unsigned long col2 = rGrp.GetUnsigned("BackgroundColor2",859006463UL);
00250 unsigned long col3 = rGrp.GetUnsigned("BackgroundColor3",2880160255UL);
00251 unsigned long col4 = rGrp.GetUnsigned("BackgroundColor4",1869583359UL);
00252 float r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
00253 r1 = ((col1 >> 24) & 0xff) / 255.0; g1 = ((col1 >> 16) & 0xff) / 255.0; b1 = ((col1 >> 8) & 0xff) / 255.0;
00254 r2 = ((col2 >> 24) & 0xff) / 255.0; g2 = ((col2 >> 16) & 0xff) / 255.0; b2 = ((col2 >> 8) & 0xff) / 255.0;
00255 r3 = ((col3 >> 24) & 0xff) / 255.0; g3 = ((col3 >> 16) & 0xff) / 255.0; b3 = ((col3 >> 8) & 0xff) / 255.0;
00256 r4 = ((col4 >> 24) & 0xff) / 255.0; g4 = ((col4 >> 16) & 0xff) / 255.0; b4 = ((col4 >> 8) & 0xff) / 255.0;
00257 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00258 (*it)->setBackgroundColor(SbColor(r1, g1, b1));
00259 if (rGrp.GetBool("UseBackgroundColorMid",false) == false)
00260 (*it)->setGradientBackgroudColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3));
00261 else
00262 (*it)->setGradientBackgroudColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3), SbColor(r4, g4, b4));
00263 }
00264 }
00265 }
00266
00267 void SplitView3DInventor::onUpdate(void)
00268 {
00269 update();
00270 }
00271
00272 const char *SplitView3DInventor::getName(void) const
00273 {
00274 return "SplitView3DInventor";
00275 }
00276
00277 bool SplitView3DInventor::onMsg(const char* pMsg, const char** ppReturn)
00278 {
00279 if (strcmp("ViewFit",pMsg) == 0 ) {
00280 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
00281 (*it)->viewAll();
00282 return true;
00283 }
00284 else if (strcmp("ViewBottom",pMsg) == 0) {
00285 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00286 SoCamera* cam = (*it)->getCamera();
00287 cam->orientation.setValue(-1, 0, 0, 0);
00288 (*it)->viewAll();
00289 }
00290 return true;
00291 }
00292 else if (strcmp("ViewFront",pMsg) == 0) {
00293 float root = (float)(sqrt(2.0)/2.0);
00294 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00295 SoCamera* cam = (*it)->getCamera();
00296 cam->orientation.setValue(-root, 0, 0, -root);
00297 (*it)->viewAll();
00298 }
00299 return true;
00300 }
00301 else if (strcmp("ViewLeft",pMsg) == 0) {
00302 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00303 SoCamera* cam = (*it)->getCamera();
00304 cam->orientation.setValue(-0.5, 0.5, 0.5, -0.5);
00305 (*it)->viewAll();
00306 }
00307 return true;
00308 }
00309 else if (strcmp("ViewRear",pMsg) == 0) {
00310 float root = (float)(sqrt(2.0)/2.0);
00311 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00312 SoCamera* cam = (*it)->getCamera();
00313 cam->orientation.setValue(0, root, root, 0);
00314 (*it)->viewAll();
00315 }
00316 return true;
00317 }
00318 else if (strcmp("ViewRight",pMsg) == 0) {
00319 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00320 SoCamera* cam = (*it)->getCamera();
00321 cam->orientation.setValue(0.5, 0.5, 0.5, 0.5);
00322 (*it)->viewAll();
00323 }
00324 return true;
00325 }
00326 else if (strcmp("ViewTop",pMsg) == 0) {
00327 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00328 SoCamera* cam = (*it)->getCamera();
00329 cam->orientation.setValue(0, 0, 0, 1);
00330 (*it)->viewAll();
00331 }
00332 return true;
00333 }
00334 else if (strcmp("ViewAxo",pMsg) == 0) {
00335 float root = (float)(sqrt(3.0)/4.0);
00336 for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
00337 SoCamera* cam = (*it)->getCamera();
00338 cam->orientation.setValue(-0.333333f, -0.166666f, -0.333333f, -root);
00339 (*it)->viewAll();
00340 }
00341 return true;
00342 }
00343
00344 return false;
00345 }
00346
00347 bool SplitView3DInventor::onHasMsg(const char* pMsg) const
00348 {
00349 if (strcmp("ViewFit",pMsg) == 0) {
00350 return true;
00351 }
00352 else if (strcmp("ViewBottom",pMsg) == 0) {
00353 return true;
00354 }
00355 else if (strcmp("ViewFront",pMsg) == 0) {
00356 return true;
00357 }
00358 else if (strcmp("ViewLeft",pMsg) == 0) {
00359 return true;
00360 }
00361 else if (strcmp("ViewRear",pMsg) == 0) {
00362 return true;
00363 }
00364 else if (strcmp("ViewRight",pMsg) == 0) {
00365 return true;
00366 }
00367 else if (strcmp("ViewTop",pMsg) == 0) {
00368 return true;
00369 }
00370 else if (strcmp("ViewAxo",pMsg) == 0) {
00371 return true;
00372 }
00373 return false;
00374 }
00375
00376 void SplitView3DInventor::setCursor(const QCursor& aCursor)
00377 {
00378
00379 }