void  CEllipsoidEditCommand::OnEnter()
{
	if (!m_was_started)
		return;
	SWITCH_RESOURCE
		ASSERT(m_editable_ellipsoid);

	double sz = m_size_panel->GetNumber();

	switch(m_scenar) 
	{
	case 0:
		m_ell_geo.Radius1 = sz;
		break;
	case 1:
		m_ell_geo.Radius2 = sz;
		break;
	case 2:
		m_ell_geo.Radius3 = sz;
		break;
	default:
		ASSERT(0);
		break;
	}

	if (fabs(m_ell_geo.Radius1)<0.0001 ||
		fabs(m_ell_geo.Radius2)<0.0001 ||
		fabs(m_ell_geo.Radius3)<0.0001)
	{
		m_message.LoadString(IDS_ERROR_ZERO_SIZE);
		m_app->PutMessage(IApplicationInterface::MT_ERROR,
			m_message);
		return;
	}
	if (m_ell_geo.Radius1<0) m_ell_geo.Radius1=-m_ell_geo.Radius1;
	if (m_ell_geo.Radius2<0) m_ell_geo.Radius2=-m_ell_geo.Radius2;
	if (m_ell_geo.Radius3<0) m_ell_geo.Radius3=-m_ell_geo.Radius3;
	sgCEllipsoid* elpsd = sgCreateEllipsoid(m_ell_geo.Radius1,
		m_ell_geo.Radius2,m_ell_geo.Radius3,m_ell_geo.MeridiansCount,
		m_ell_geo.ParallelsCount);
	if (!elpsd)
		return;
	elpsd->InitTempMatrix()->Multiply(*m_matr);
	elpsd->ApplyTempMatrix();
	elpsd->DestroyTempMatrix();

	sgGetScene()->StartUndoGroup();
	sgGetScene()->DetachObject(m_editable_ellipsoid);
	sgGetScene()->AttachObject(elpsd);
	sgGetScene()->EndUndoGroup();
	m_app->CopyAttributes(*elpsd,*m_editable_ellipsoid);
	m_app->GetViewPort()->InvalidateViewPort();

	m_app->StopCommander();
}
void OnBnClickedPrEllipsoids()
{
  sgGetScene()->Clear();

  AddFloorInScene(100.0, 50.0, 50.0, 10.0, 2.0);

  for (int i=3;i<10;i++)
  {
    sgCEllipsoid* ell1 = sgCreateEllipsoid(i,i/6+2,2*i, 24,24);
    //SetMaterialToObject(ell1,MATERIAL_GLASS_1+i);
    SG_POINT rotCen = {0.0,0.0,0.0};
    SG_VECTOR rotDir = {rand(),rand(),rand()};
    ell1->InitTempMatrix()->Rotate(rotCen,rotDir, rand()*360);
    SG_VECTOR transV1 = {10*i,10,10};
    ell1->GetTempMatrix()->Translate(transV1);
    ell1->ApplyTempMatrix();
    ell1->DestroyTempMatrix();

    sgGetScene()->AttachObject(ell1);
    ell1->SetAttribute(SG_OA_COLOR,i);
    
  }
}
void  CEllipsoidEditCommand::LeftClick(unsigned int nFlags,int pX,int pY)
{
	if (!m_was_started)
		return;
	SWITCH_RESOURCE
		ASSERT(m_editable_ellipsoid);

	if (fabs(m_ell_geo.Radius1)<0.0001 ||
		fabs(m_ell_geo.Radius2)<0.0001 ||
		fabs(m_ell_geo.Radius3)<0.0001)
	{
		m_message.LoadString(IDS_ERROR_ZERO_SIZE);
		m_app->PutMessage(IApplicationInterface::MT_ERROR,
			m_message);
		return;
	}
	if (m_ell_geo.Radius1<0) m_ell_geo.Radius1=-m_ell_geo.Radius1;
	if (m_ell_geo.Radius2<0) m_ell_geo.Radius2=-m_ell_geo.Radius2;
	if (m_ell_geo.Radius3<0) m_ell_geo.Radius3=-m_ell_geo.Radius3;
	sgCEllipsoid* elpsd = sgCreateEllipsoid(m_ell_geo.Radius1,
		m_ell_geo.Radius2,m_ell_geo.Radius3,m_ell_geo.MeridiansCount,
		m_ell_geo.ParallelsCount);
	if (!elpsd)
		return;
	elpsd->InitTempMatrix()->Multiply(*m_matr);
	elpsd->ApplyTempMatrix();
	elpsd->DestroyTempMatrix();

	sgGetScene()->StartUndoGroup();
	sgGetScene()->DetachObject(m_editable_ellipsoid);
	sgGetScene()->AttachObject(elpsd);
	sgGetScene()->EndUndoGroup();
	m_app->CopyAttributes(*elpsd,*m_editable_ellipsoid);
	m_app->GetViewPort()->InvalidateViewPort();

	m_app->StopCommander();
}