← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3818: Better behavior of QGLViewer for shift+select and moving bodies (fixes LP bug 806469)

 

------------------------------------------------------------
revno: 3818
committer: Bruno Chareyre <bruno.chareyre@xxxxxxxxxxxxxxx>
timestamp: Sun 2014-02-16 15:03:41 +0100
message:
  Better behavior of QGLViewer for shift+select and moving bodies (fixes LP bug 806469)
modified:
  gui/qt4/GLViewer.cpp
  gui/qt4/GLViewer.hpp
  gui/qt4/GLViewerDisplay.cpp
  pkg/dem/NewtonIntegrator.cpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'gui/qt4/GLViewer.cpp'
--- gui/qt4/GLViewer.cpp	2013-10-14 20:51:11 +0000
+++ gui/qt4/GLViewer.cpp	2014-02-16 14:03:41 +0000
@@ -35,7 +35,6 @@
 	#include<gl2ps.h>
 #endif
 
-static int last(-1);
 static unsigned initBlocked(State::DOF_NONE);
 
 CREATE_LOGGER(GLViewer);
@@ -65,7 +64,7 @@
 	cut_plane_delta = -2;
 	gridSubdivide = false;
 	resize(550,550);
-
+	last=-1;
 	if(viewId==0) setWindowTitle("Primary view");
 	else setWindowTitle(("Secondary view #"+lexical_cast<string>(viewId)).c_str());
 
@@ -87,6 +86,7 @@
 	setKeyDescription(Qt::Key_D,"Toggle time display mask");
 	setKeyDescription(Qt::Key_G,"Toggle grid visibility; g turns on and cycles");
 	setKeyDescription(Qt::Key_G & Qt::ShiftModifier ,"Hide grid.");
+	setKeyDescription(Qt::Key_M, "Move selected object.");
 	setKeyDescription(Qt::Key_X,"Show the xz [shift: xy] (up-right) plane (clip plane: align normal with +x)");
 	setKeyDescription(Qt::Key_Y,"Show the yx [shift: yz] (up-right) plane (clip plane: align normal with +y)");
 	setKeyDescription(Qt::Key_Z,"Show the zy [shift: zx] (up-right) plane (clip plane: align normal with +z)");
@@ -224,8 +224,18 @@
 	else if(e->key()==Qt::Key_D) {timeDispMask+=1; if(timeDispMask>(TIME_REAL|TIME_VIRT|TIME_ITER))timeDispMask=0; }
 	else if(e->key()==Qt::Key_G) { if(e->modifiers() & Qt::ShiftModifier){ drawGrid=0; return; } else drawGrid++; if(drawGrid>=8) drawGrid=0; }
 	else if (e->key()==Qt::Key_M && selectedName() >= 0){ 
-		if(!(isMoving=!isMoving)){displayMessage("Moving done."); if (last>=0) {Body::byId(Body::id_t(last))->state->blockedDOFs=initBlocked; last=-1; Omega::instance().getScene()->selectedBody = -1;} mouseMovesCamera();}
-		else{ displayMessage("Moving selected object"); mouseMovesManipulatedFrame();}
+		if(!(isMoving=!isMoving)){
+			displayMessage("Moving done.");
+			if (last>=0) {Body::byId(Body::id_t(last))->state->blockedDOFs=initBlocked; last=-1;} mouseMovesCamera();}
+		else{ 	displayMessage("Moving selected object");
+			
+			long selection = Omega::instance().getScene()->selectedBody;
+			initBlocked=Body::byId(Body::id_t(selection))->state->blockedDOFs; last=selection;
+			Body::byId(Body::id_t(selection))->state->blockedDOFs=State::DOF_ALL;
+			Quaternionr& q = Body::byId(selection)->state->ori;
+			Vector3r&    v = Body::byId(selection)->state->pos;
+			manipulatedFrame()->setPositionAndOrientation(qglviewer::Vec(v[0],v[1],v[2]),qglviewer::Quaternion(q.x(),q.y(),q.z(),q.w()));
+			mouseMovesManipulatedFrame();}
 	}
 	else if (e->key() == Qt::Key_T) camera()->setType(camera()->type()==qglviewer::Camera::ORTHOGRAPHIC ? qglviewer::Camera::PERSPECTIVE : qglviewer::Camera::ORTHOGRAPHIC);
 	else if(e->key()==Qt::Key_O) camera()->setFieldOfView(camera()->fieldOfView()*0.9);
@@ -393,19 +403,15 @@
 	}
 	if(selection>=0 && (*(Omega::instance().getScene()->bodies)).exists(selection)){
 		resetManipulation();
+		if (last>=0) {Body::byId(Body::id_t(last))->state->blockedDOFs=initBlocked; last=-1;}
 		if(Body::byId(Body::id_t(selection))->isClumpMember()){ // select clump (invisible) instead of its member
 			LOG_DEBUG("Clump member #"<<selection<<" selected, selecting clump instead.");
 			selection=Body::byId(Body::id_t(selection))->clumpId;			
 		}
-		initBlocked=Body::byId(Body::id_t(selection))->state->blockedDOFs;
-		Body::byId(Body::id_t(selection))->state->blockedDOFs=State::DOF_ALL;
 		
 		setSelectedName(selection);
 		LOG_DEBUG("New selection "<<selection);
 		displayMessage("Selected body #"+lexical_cast<string>(selection)+(Body::byId(selection)->isClump()?" (clump)":""));
-		Quaternionr& q = Body::byId(selection)->state->ori;
-		Vector3r&    v = Body::byId(selection)->state->pos;
-		manipulatedFrame()->setPositionAndOrientation(qglviewer::Vec(v[0],v[1],v[2]),qglviewer::Quaternion(q.x(),q.y(),q.z(),q.w()));
 		Omega::instance().getScene()->selectedBody = selection;
 			PyGILState_STATE gstate;
 			gstate = PyGILState_Ensure();

=== modified file 'gui/qt4/GLViewer.hpp'
--- gui/qt4/GLViewer.hpp	2013-03-14 20:01:49 +0000
+++ gui/qt4/GLViewer.hpp	2014-02-16 14:03:41 +0000
@@ -49,6 +49,7 @@
 		float			cut_plane;
 		int			cut_plane_delta;
 		bool			gridSubdivide;
+		long			last;
 		int manipulatedClipPlane;
 		set<int> boundClipPlanes;
 		shared_ptr<qglviewer::LocalConstraint> xyPlaneConstraint;

=== modified file 'gui/qt4/GLViewerDisplay.cpp'
--- gui/qt4/GLViewerDisplay.cpp	2013-10-16 05:48:14 +0000
+++ gui/qt4/GLViewerDisplay.cpp	2014-02-16 14:03:41 +0000
@@ -89,7 +89,6 @@
 		int selection = selectedName();
 		if(selection!=-1 && (*(Omega::instance().getScene()->bodies)).exists(selection) && isMoving){
 			static Real lastTimeMoved(0);
-			static Real initv0(0); static Real initv1(0); static Real initv2(0);
 			float v0,v1,v2; manipulatedFrame()->getPosition(v0,v1,v2);
 			if(last == selection) // delay by one redraw, so the body will not jump into 0,0,0 coords
 			{
@@ -98,22 +97,13 @@
 				Vector3r&    vel = (*(Omega::instance().getScene()->bodies))[selection]->state->vel;
 				Vector3r&    angVel = (*(Omega::instance().getScene()->bodies))[selection]->state->angVel;
 				angVel=Vector3r::Zero(); 
-				if (!initv0 && !initv1 && !initv2){initv0=v0;initv1=v1;initv2=v2;}
-				if (initv0!=v0 || initv1!=v1 || initv2!=v2) {
-					Real dt=(scene->time-lastTimeMoved); lastTimeMoved=scene->time;
-					if (dt!=0) { 
-						vel[0]=-(v[0]-v0)/dt; vel[1]=-(v[1]-v1)/dt; vel[2]=-(v[2]-v2)/dt;
-						vel[0]=-(initv0-v0)/dt; vel[1]=-(initv1-v1)/dt; vel[2]=-(initv2-v2)/dt;
-						initv0=v0;initv1=v1;initv2=v2;
-					}
-				}
-				else {vel[0]=vel[1]=vel[2]=0; /*v[0]=v0;v[1]=v1;v[2]=v2;*/}
-				v[0]=v0;v[1]=v1;v[2]=v2;
+				Real dt=(scene->time-lastTimeMoved); lastTimeMoved=scene->time;
+				if (dt!=0) { vel[0]=-(v[0]-v0)/dt; vel[1]=-(v[1]-v1)/dt; vel[2]=-(v[2]-v2)/dt;}
+				else vel[0]=vel[1]=vel[2]=0;
 				//FIXME: should update spin like velocity above, when the body is rotated:
 				double q0,q1,q2,q3; manipulatedFrame()->getOrientation(q0,q1,q2,q3);	q.x()=q0;q.y()=q1;q.z()=q2;q.w()=q3;
 			}
 			(*(Omega::instance().getScene()->bodies))[selection]->userForcedDisplacementRedrawHook();	
-			last=selection;
 		}
 		if(manipulatedClipPlane>=0){
 			assert(manipulatedClipPlane<renderer->numClipPlanes);

=== modified file 'pkg/dem/NewtonIntegrator.cpp'
--- pkg/dem/NewtonIntegrator.cpp	2013-05-14 21:24:11 +0000
+++ pkg/dem/NewtonIntegrator.cpp	2014-02-16 14:03:41 +0000
@@ -224,7 +224,7 @@
 	//NOTE : dVel defined without wraping the coordinates means bodies out of the (0,0,0) period can move realy fast. It has to be compensated properly in the definition of relative velocities (see Ig2 functors and contact laws).
 		//Reflect mean-field (periodic cell) acceleration in the velocity
 	if(scene->isPeriodic && homoDeform) {Vector3r dVel=dVelGrad*state->pos; state->vel+=dVel;}
-	if (!bodySelected || scene->selectedBody!=id) state->pos+=state->vel*dt;
+	state->pos+=state->vel*dt;
 }
 
 void NewtonIntegrator::leapfrogSphericalRotate(State* state, const Body::id_t& id, const Real& dt )