Пример #1
0
void Dlg_EditPrim::ChangedDX(double NewVal)
{
	ui.DXSlider->setValue(NewVal*100); //keep the slider buddy-buddy
	CPrimitive* pPrim = pVXRegion->GetRegion();

	if (!AutoUpdating){
		AutoUpdating = true;
		if (pVXRegion){ //if we've got a current region
			double NewDX = NewVal;
			double NewDY = pPrim->dY;
			double NewDZ = pPrim->dZ;
			double NewX = pPrim->X;
			double NewY = pPrim->Y;
			double NewZ = pPrim->Z;
			double NewRad = pPrim->Radius;

			if (Snap) NewDX = GetSnapped(NewDX, 1.0/pObj->GetVXDim(), false); //if snapping to voxel is enabled
			
			if (pVXRegion->IsCylinder()){
				if(NewDX != 0) {
					NewDY=0; //keep cylinder on a principle axis!
					NewDZ=0;
					if (LockAspect) NewRad = NewDX*pPrim->_NomAspect.y/2/pPrim->_NomAspect.x;
				} 
			} 
			else if (pVXRegion->IsBox()){ // || pVXRegion->IsMesh()){
				if (LockAspect){
					NewDY = NewDX*pPrim->_NomAspect.y/pPrim->_NomAspect.x;
					NewDZ = NewDX*pPrim->_NomAspect.z/pPrim->_NomAspect.x;
					if (NewDY>1) {NewDX/=NewDY; NewDZ/=NewDY; NewDY=1.0;}//keep any from going above 1...
					if (NewDZ>1) {NewDX/=NewDZ; NewDY/=NewDZ; NewDZ=1.0;}//keep any from going above 1...
					if (NewDX + NewX > 1.0) NewX=1.0-NewDX;
					if (NewDY + NewY > 1.0) NewY=1.0-NewDY;
					if (NewDZ + NewZ > 1.0) NewZ=1.0-NewDZ;
				}
				else if (NewDX + NewX > 1.0) NewX=1.0-NewDX;  //if increasing the size pushes out the end, push location back
			}

			//Update variables/sliders
			pPrim->X = NewX; ChangedX(NewX);
			pPrim->Y = NewY; ChangedY(NewY);
			pPrim->Z = NewZ; ChangedZ(NewZ);
			pPrim->dX = NewDX; ChangedDX(NewDX);
			pPrim->dY = NewDY; ChangedDY(NewDY);
			pPrim->dZ = NewDZ; ChangedDZ(NewDZ);
			pPrim->Radius = NewRad; ChangedRad(NewRad);


			pPrim->UpdateAspect(); //This only does something if aspect ratio changes...

		}
		emit RequestUpdateGL();
		AutoUpdating = false;
	}

}
Пример #2
0
void Dlg_EditPrim::ChangedX(double NewVal)
{
	ui.XSlider->setValue(NewVal*100);
	CPrimitive* pPrim = pVXRegion->GetRegion();

	if (!AutoUpdating){
		AutoUpdating = true;
		if (pVXRegion){
			double NewX = NewVal;

			if (pVXRegion->IsBox() && NewX + pPrim->dX > 1.0) NewX = 1.0 - pPrim->dX;//if this BC would be outside the workspace, keep it within
			if (Snap) NewX = GetSnapped(NewX, 1.0/pObj->GetVXDim());

			//Update variables/sliders
			pPrim->X = NewX; ChangedX(NewX);

		}
		emit RequestUpdateGL();
		AutoUpdating = false;
	}
}
Пример #3
0
void StickWidget::handleMouseEvent(QMouseEvent* event)
{
  if (event->button() == Qt::RightButton)
  {
    m_x = std::round(m_max_x / 2.);
    m_y = std::round(m_max_y / 2.);
  }
  else
  {
    // convert from widget space to value space
    int new_x = (event->x() * m_max_x) / width();
    int new_y = m_max_y - (event->y() * m_max_y) / height();

    m_x = std::max(0, std::min(static_cast<int>(m_max_x), new_x));
    m_y = std::max(0, std::min(static_cast<int>(m_max_y), new_y));
  }

  emit ChangedX(m_x);
  emit ChangedY(m_y);
  update();
}