yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #05593
[Branch ~yade-dev/yade/trunk] Rev 2418: 1. Fix bugs related to 3d views (centering, secondary views, closing views). Thanks to Sega for r...
------------------------------------------------------------
revno: 2418
fixes bug(s): https://launchpad.net/bugs/626172 https://launchpad.net/bugs/625747
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Sun 2010-08-29 12:39:02 +0200
message:
1. Fix bugs related to 3d views (centering, secondary views, closing views). Thanks to Sega for reporting.
modified:
gui/SConscript
gui/qt4/GLViewer.cpp
gui/qt4/OpenGLManager.cpp
gui/qt4/OpenGLManager.hpp
gui/qt4/_GLViewer.cpp
gui/qt4/__init__.py
gui/qt4/controller.ui
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'gui/SConscript'
--- gui/SConscript 2010-08-15 16:30:00 +0000
+++ gui/SConscript 2010-08-29 10:39:02 +0000
@@ -9,10 +9,10 @@
env.File('qt4/SerializableEditor.py'),
env.File('qt4/Inspector.py'),
env.File('qt4/__init__.py'),
- env.SharedLibrary('_GLViewer',['qt4/_GLViewer.cpp','qt4/OpenGLManager.cpp'],SHLIBPREFIX='',LIBS=env['LIBS']+['GLViewer'],RPATH=env['RPATH']+[env.Literal('\\$$ORIGIN/../../../gui')])
+ env.SharedLibrary('_GLViewer',['qt4/GLViewer.cpp','qt4/_GLViewer.cpp','qt4/OpenGLManager.cpp'],SHLIBPREFIX='',LIBS=env['LIBS']+[env['QGLVIEWER_LIB']],RPATH=env['RPATH']+[env.Literal('\\$$ORIGIN/../../../gui')])
])
env.Command('qt4/img_rc.py','qt4/img.qrc','pyrcc4 -o $buildDir/gui/qt4/img_rc.py gui/qt4/img.qrc')
env.Command('qt4/ui_controller.py','qt4/controller.ui','pyuic4 -o $buildDir/gui/qt4/ui_controller.py gui/qt4/controller.ui')
- env.Install('$PREFIX/lib/yade$SUFFIX/gui',[
- env.SharedLibrary('GLViewer',['qt4/GLViewer.cpp'],LIBS=env['LIBS']+[env['QGLVIEWER_LIB']]+linkPlugins(['OpenGLRenderer']))
- ])
+ #env.Install('$PREFIX/lib/yade$SUFFIX/gui',[
+ # env.SharedLibrary('GLViewer',['qt4/GLViewer.cpp'],LIBS=env['LIBS']+[env['QGLVIEWER_LIB']]+linkPlugins(['OpenGLRenderer']))
+ #])
=== modified file 'gui/qt4/GLViewer.cpp'
--- gui/qt4/GLViewer.cpp 2010-08-16 21:31:08 +0000
+++ gui/qt4/GLViewer.cpp 2010-08-29 10:39:02 +0000
@@ -61,10 +61,12 @@
}
#endif
-GLViewer::~GLViewer(){ /* get the GL mutex when closing */ GLLock lock(this); cerr<<"Destructing view #"<<viewId<<endl; }
+GLViewer::~GLViewer(){ /* get the GL mutex when closing */ GLLock lock(this); /* cerr<<"Destructing view #"<<viewId<<endl;*/ }
void GLViewer::closeEvent(QCloseEvent *e){
- // OpenGLManager::self->closeView(viewId);
+ LOG_DEBUG("Will emit closeView for view #"<<viewId);
+ OpenGLManager::self->emitCloseView(viewId);
+ e->accept();
}
GLViewer::GLViewer(int _viewId, const shared_ptr<OpenGLRenderer>& _renderer, QGLWidget* shareWidget): QGLViewer(/*parent*/(QWidget*)NULL,shareWidget), renderer(_renderer), viewId(_viewId) {
@@ -397,15 +399,18 @@
Vector3r min,max;
if(rb->bound){
min=rb->bound->min; max=rb->bound->max;
- if(std::max(max[0]-min[0],std::max(max[1]-min[1],max[2]-min[2]))<=0){
+ bool hasNan=(isnan(min[0])||isnan(min[1])||isnan(min[2])||isnan(max[0])||isnan(max[1])||isnan(max[2]));
+ Real minDim=std::min(max[0]-min[0],std::min(max[1]-min[1],max[2]-min[2]));
+ if(minDim<=0 || hasNan){
// Aabb is not yet calculated...
- LOG_DEBUG("scene's bound not yet calculated or has one dimension zero, attempt get that from bodies' positions.");
+ LOG_DEBUG("scene's bound not yet calculated or has zero or nan dimension(s), attempt get that from bodies' positions.");
Real inf=std::numeric_limits<Real>::infinity();
min=Vector3r(inf,inf,inf); max=Vector3r(-inf,-inf,-inf);
FOREACH(const shared_ptr<Body>& b, *rb->bodies){
max=max.cwise().max(b->state->pos);
min=min.cwise().min(b->state->pos);
}
+ if(isinf(min[0])||isinf(min[1])||isinf(min[2])||isinf(max[0])||isinf(max[1])||isinf(max[2])){ LOG_DEBUG("No min/max computed from bodies either, setting cube (-1,-1,-1)Ã(1,1,1)"); min=-Vector3r::Ones(); max=Vector3r::Ones(); }
} else {LOG_DEBUG("Using scene's Aabb");}
} else {
LOG_DEBUG("No scene's Aabb; setting scene in cube (-1,-1,-1)x(1,1,1)");
=== modified file 'gui/qt4/OpenGLManager.cpp'
--- gui/qt4/OpenGLManager.cpp 2010-07-24 18:10:24 +0000
+++ gui/qt4/OpenGLManager.cpp 2010-08-29 10:39:02 +0000
@@ -47,6 +47,7 @@
views.resize(views.size()-1); // releases the pointer as well
}
if(id==0){
+ LOG_DEBUG("Closing primary view.");
if(views.size()==1) views.clear();
else{ LOG_INFO("Cannot close primary view, secondary views still exist."); }
}
=== modified file 'gui/qt4/OpenGLManager.hpp'
--- gui/qt4/OpenGLManager.hpp 2010-07-24 18:10:24 +0000
+++ gui/qt4/OpenGLManager.hpp 2010-08-29 10:39:02 +0000
@@ -22,6 +22,7 @@
void emitResizeView(int id, int wd, int ht){ emit resizeView(id,wd,ht); }
void emitCreateView(){ emit createView(); }
void emitStartTimer(){ emit startTimerSignal(); }
+ void emitCloseView(int id){ emit closeView(id); }
signals:
void createView();
void resizeView(int id, int wd, int ht);
=== modified file 'gui/qt4/_GLViewer.cpp'
--- gui/qt4/_GLViewer.cpp 2010-07-27 12:37:10 +0000
+++ gui/qt4/_GLViewer.cpp 2010-08-29 10:39:02 +0000
@@ -5,6 +5,7 @@
#include<yade/lib-pyutil/doc_opts.hpp>
#include<QApplication>
+#include<QCloseEvent>
#ifdef YADE_LOG4CXX
log4cxx::LoggerPtr logger=log4cxx::Logger::getLogger("yade.qt4");
@@ -37,6 +38,7 @@
public:
#define GLV if((OpenGLManager::self->views.size()<=viewNo) || !(OpenGLManager::self->views[viewNo])) throw runtime_error("No view #"+lexical_cast<string>(viewNo)); GLViewer* glv=OpenGLManager::self->views[viewNo].get();
pyGLViewer(size_t _viewNo=0): viewNo(_viewNo){}
+ void close(){ GLV; QCloseEvent* e(new QCloseEvent); QApplication::postEvent(glv,e); }
py::tuple get_grid(){GLV; return py::make_tuple(glv->drawGridXYZ[0],glv->drawGridXYZ[1],glv->drawGridXYZ[2]);}
void set_grid(py::tuple t){GLV; for(int i=0;i<3;i++)glv->drawGridXYZ[i]=py::extract<bool>(t[i])();}
#define VEC_GET_SET(property,getter,setter) Vector3r get_##property(){GLV; qglviewer::Vec v=getter(); return Vector3r(v[0],v[1],v[2]); } void set_##property(const Vector3r& t){GLV; setter(qglviewer::Vec(t[0],t[1],t[2]));}
@@ -113,6 +115,7 @@
.def("saveState",&pyGLViewer::saveDisplayParameters,(py::arg("slot")),"Save display parameters into numbered memory slot. Saves state for both :yref:`GLViewer<yade._qt.GLViewer>` and associated :yref:`OpenGLRenderer`.")
.def("loadState",&pyGLViewer::useDisplayParameters,(py::arg("slot")),"Load display parameters from slot saved previously into, identified by its number.")
.def("__repr__",&pyGLViewer::pyStr).def("__str__",&pyGLViewer::pyStr)
+ .def("close",&pyGLViewer::close)
.add_property("selection",&pyGLViewer::get_selection,&pyGLViewer::set_selection)
;
}
=== modified file 'gui/qt4/__init__.py'
--- gui/qt4/__init__.py 2010-08-26 16:56:07 +0000
+++ gui/qt4/__init__.py 2010-08-29 10:39:02 +0000
@@ -156,13 +156,19 @@
def pauseSlot(self): O.pause()
def stepSlot(self): O.step()
def subStepSlot(self,value): O.subStepping=bool(value)
- def new3dSlot(self): View()
+ def show3dSlot(self, show):
+ vv=views()
+ assert(len(vv) in (0,1))
+ if show:
+ if len(vv)==0: View()
+ else:
+ if len(vv)>0: vv[0].close()
def setReferenceSlot(self):
for b in O.bodies:
b.state.refPos=b.state.pos
b.state.refOri=b.state.ori
def centerSlot(self):
- centerAllViews()
+ for v in views(): v.center()
def setViewAxes(self,dir,up):
try:
v=views()[0]
@@ -240,6 +246,7 @@
self.iterLabel.setText('#%ld / %ld, %.1f/s %s'%(O.iter,stopAtIter,iterPerSec,subStepInfo))
s=int(t); ms=int(t*1000)%1000; us=int(t*1000000)%1000; ns=int(t*1000000000)%1000
self.virtTimeLabel.setText(u'%03ds%03dm%03dμ%03dn'%(s,ms,us,ns))
+ self.show3dButton.setChecked(len(views())>0)
def Generator():
global controller
=== modified file 'gui/qt4/controller.ui'
--- gui/qt4/controller.ui 2010-08-26 16:56:07 +0000
+++ gui/qt4/controller.ui 2010-08-29 10:39:02 +0000
@@ -420,9 +420,12 @@
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
- <widget class="QPushButton" name="new3dButton">
+ <widget class="QPushButton" name="show3dButton">
<property name="text">
- <string>New 3D</string>
+ <string>Show 3D</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
</property>
</widget>
</item>
@@ -844,22 +847,6 @@
</hints>
</connection>
<connection>
- <sender>new3dButton</sender>
- <signal>clicked()</signal>
- <receiver>Controller</receiver>
- <slot>new3dSlot()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>93</x>
- <y>429</y>
- </hint>
- <hint type="destinationlabel">
- <x>5</x>
- <y>469</y>
- </hint>
- </hints>
- </connection>
- <connection>
<sender>referenceButton</sender>
<signal>clicked()</signal>
<receiver>Controller</receiver>
@@ -946,8 +933,8 @@
<slot>generateSlot()</slot>
<hints>
<hint type="sourcelabel">
- <x>280</x>
- <y>490</y>
+ <x>101</x>
+ <y>60</y>
</hint>
<hint type="destinationlabel">
<x>284</x>
@@ -994,8 +981,8 @@
<slot>generatorComboSlot()</slot>
<hints>
<hint type="sourcelabel">
- <x>104</x>
- <y>58</y>
+ <x>101</x>
+ <y>60</y>
</hint>
<hint type="destinationlabel">
<x>284</x>
@@ -1099,6 +1086,22 @@
</hint>
</hints>
</connection>
+ <connection>
+ <sender>show3dButton</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>Controller</receiver>
+ <slot>show3dSlot(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>42</x>
+ <y>418</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>-2</x>
+ <y>422</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
<slots>
<slot>loadSlot()</slot>
@@ -1107,7 +1110,6 @@
<slot>playSlot()</slot>
<slot>pauseSlot()</slot>
<slot>stepSlot()</slot>
- <slot>new3dSlot()</slot>
<slot>setReferenceSlot()</slot>
<slot>centerSlot()</slot>
<slot>dtFixedSlot()</slot>
@@ -1124,5 +1126,6 @@
<slot>pythonEditSlot()</slot>
<slot>inspectSlot()</slot>
<slot>subStepSlot()</slot>
+ <slot>show3dSlot(bool)</slot>
</slots>
</ui>