Beispiel #1
0
void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
{
    wxASSERT_MSG(m_control,
                 wxT("The wxGridCellEditor must be created first!"));

    if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
    {
        m_value = grid->GetTable()->GetValueAsBool(row, col);
    }
    else
    {
        wxString cellval( grid->GetTable()->GetValue(row, col) );

        if ( cellval == ms_stringValues[false] )
            m_value = false;
        else if ( cellval == ms_stringValues[true] )
            m_value = true;
        else
        {
            // do not try to be smart here and convert it to true or false
            // because we'll still overwrite it with something different and
            // this risks to be very surprising for the user code, let them
            // know about it
            wxFAIL_MSG( wxT("invalid value for a cell with bool editor!") );
        }
    }

    CBox()->SetValue(m_value);
    CBox()->SetFocus();
}
Beispiel #2
0
void CShape::KillGLLists()
{
	if (m_face_gl_list)
	{
		glDeleteLists(m_face_gl_list, 1);
		m_face_gl_list = 0;
	}

	if (m_edge_gl_list)
	{
		glDeleteLists(m_edge_gl_list, 1);
		m_edge_gl_list = 0;
	}

	m_box = CBox();

	if(m_faces)
	{
		for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild())
		{
			CFace* f = (CFace*)object;
			f->KillMarkingGLList();
		}
	}
}
Beispiel #3
0
void wxGridCellBoolEditor::Reset()
{
    wxASSERT_MSG(m_control,
                 wxT("The wxGridCellEditor must be created first!"));

    CBox()->SetValue(m_value);
}
Beispiel #4
0
CBSPTree::CBSPTree( CModel *model ):
_root(0){

	for( int i=0;i<model->Surfaces().size();++i ){
		CModelSurface *surf=(CModelSurface*)model->Surfaces()[i]->Copy();
		cout<<"Adding surface, verts="<<surf->Vertices().size()<<", tris="<<surf->Triangles().size()<<endl;
		_surfaces.push_back( surf );
	}
	
	vector<CPolygon*> polys;
	
	for( int i=0;i<_surfaces.size();++i ){
		CModelSurface *surf=_surfaces[i];
		
		vector<int> verts(3);

		for( vector<CTriangle>::const_iterator it=surf->Triangles().begin();it!=surf->Triangles().end();++it ){
			const CTriangle &tri=*it;
			verts[0]=tri.vertices[0];
			verts[1]=tri.vertices[1];
			verts[2]=tri.vertices[2];
			CPolygon *poly=new CPolygon( surf,verts );
			polys.push_back( new CPolygon( surf,verts ) );
		}
	}
	
	if( !polys.size() ){
		_root=new CBSPNode( CPlane( CVec3(0,1,0),0 ) );
		return;
	}
	
	_root=new CBSPNode( polys[0]->Plane() );

	for( int i=1;i<polys.size();++i ){
		_root->InsertPlane( polys[i] );
	}

	for( int i=0;i<polys.size();++i ){
		_root->InsertLeaf( polys[i] );
	}

	for( int i=0;i<polys.size();++i ){
//		_root->InsertPolygon( polys[i] );
	}

	CPlane plane( CVec3(0,1,0),-5 );
	
//	_root=new CBSPNode( plane,new CBSPNode( 1 ),0 );
	
	_hpSurface=new CModelSurface;
	CPolygon *poly=new CPolygon( _hpSurface,plane,CBox( CVec3(-50),CVec3(50) ) );
	CBSPNode *bits[2];
	_root->Split( poly,bits );
	_root=new CBSPNode( plane,bits[0],0 );

	for( int i=0;i<polys.size();++i ){
		_root->InsertPolygon( polys[i] );
	}
}
Beispiel #5
0
CBox * CBox::create() {
    CBox * pRet = NEW CBox();
    if (pRet) {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
Beispiel #6
0
void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
{
    int keycode = event.GetKeyCode();
    switch ( keycode )
    {
        case WXK_SPACE:
            CBox()->SetValue(!CBox()->GetValue());
            break;

        case '+':
            CBox()->SetValue(true);
            break;

        case '-':
            CBox()->SetValue(false);
            break;
    }
}
Beispiel #7
0
///////////////////////////////////////////////////////////////
//
// CSpatialDatabaseImpl::FlushUpdateQueue
//
// Process all entities that have changed since the last call
//
///////////////////////////////////////////////////////////////
void CSpatialDatabaseImpl::FlushUpdateQueue ( void )
{
    int iTotalUpdated = 0;

    for ( std::map < CElement*, int >::iterator it = m_UpdateQueue.begin (); it != m_UpdateQueue.end (); ++it )
    {
        CElement* pEntity = it->first;

        // Get the new bounding box
        SEntityInfo newInfo;
        CSphere sphere = pEntity->GetWorldBoundingSphere ();
        newInfo.box = CBox ( sphere.vecPosition, fabsf ( sphere.fRadius ) );
        // Make everything 2D for now
        newInfo.box.vecMin.fZ = SPATIAL_2D_Z;
        newInfo.box.vecMax.fZ = SPATIAL_2D_Z;

        // Get previous info
        if ( SEntityInfo* pOldInfo = MapFind ( m_InfoMap, pEntity ) )
        {
            // Don't update if bounding box is the same
            if ( pOldInfo->box == newInfo.box )
                continue;

            // Remove old bounding box from tree
            m_Tree.Remove ( &pOldInfo->box.vecMin.fX, &pOldInfo->box.vecMax.fX, pEntity );
        }

        if ( !IsValidSphere ( sphere ) )
            continue;

        // Add new bounding box
        m_Tree.Insert( &newInfo.box.vecMin.fX, &newInfo.box.vecMax.fX, pEntity );

        // Update info map
        MapSet ( m_InfoMap, pEntity, newInfo );
        iTotalUpdated++;
#ifdef SPATIAL_DATABASE_DEBUG_OUTPUTA
        OutputDebugLine ( SString ( "SpatialDatabase::UpdateEntity %08x  %2.0f,%2.0f,%2.0f   %2.0f,%2.0f,%2.0f"
                                    ,pEntity
                                    ,info.box.vecMin.fX
                                    ,info.box.vecMin.fY
                                    ,info.box.vecMin.fZ
                                    ,info.box.vecMax.fX
                                    ,info.box.vecMax.fY
                                    ,info.box.vecMax.fZ
                                  ) );
#endif
    }
    m_UpdateQueue.clear ();

#ifdef SPATIAL_DATABASE_DEBUG_OUTPUTB
    int iTotalToUpdate = m_UpdateQueue.size ();
    if ( iTotalToUpdate )
        OutputDebugLine ( SString ( "SpatialDatabase::FlushUpdateQueue  TotalToUpdate: %d   TotalUpdated: %d  m_InfoMap: %d    tree: %d  ", iTotalToUpdate, iTotalUpdated, m_InfoMap.size (), m_Tree.Count () ) );
#endif
}
Beispiel #8
0
void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
{
    m_control->Show(show);

    if ( show )
    {
        wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
        CBox()->SetBackgroundColour(colBg);
    }
}
Beispiel #9
0
void CFuzzyVariable::load (ifstream& file) {
	
	string ignore; file >> ignore;
	
	int left, top, right, bottom;
	file >> ignore >> left >> top >> right >> bottom;
	box = CBox (left, top, right, bottom);	
	
	int n; file >> ignore >> n;
	for (int i = 0; i < n; i++) mfs.push_back (new CMembershipFunction(file));
}
Beispiel #10
0
CWaterline::CWaterline(const std::list<int> &solids, const int tool_number)
    :CDepthOp(GetTypeString(), NULL, tool_number, WaterlineType), m_solids(solids)
{
	ReadDefaultValues();

	// set m_box from the extents of the solids
	for(std::list<int>::const_iterator It = solids.begin(); It != solids.end(); It++)
	{
		int solid = *It;
		HeeksObj* object = heeksCAD->GetIDObject(SolidType, solid);
		if(object)
		{
			if(object->GetType() == StlSolidType)
			{
				object->GetBox(m_params.m_box);
			}
			else
			{
				double extents[6];
				if(heeksCAD->BodyGetExtents(object, extents))
				{
					m_params.m_box.Insert(CBox(extents));
				}
			}

			Add(object, NULL);
		}
	}
	m_solids.clear();

	SetDepthOpParamsFromBox();

	// add tool radius all around the box
	if(m_params.m_box.m_valid)
	{
		CTool *pTool = CTool::Find(m_tool_number);
		if(pTool)
		{
			double extra = pTool->m_params.m_diameter/2 + 0.01;
			m_params.m_box.m_x[0] -= extra;
			m_params.m_box.m_x[1] -= extra;
			m_params.m_box.m_x[3] += extra;
			m_params.m_box.m_x[4] += extra;
		}
	}
}
Beispiel #11
0
bool wxGridCellBoolEditor::EndEdit(int WXUNUSED(row),
                                   int WXUNUSED(col),
                                   const wxGrid* WXUNUSED(grid),
                                   const wxString& WXUNUSED(oldval),
                                   wxString *newval)
{
    bool value = CBox()->GetValue();
    if ( value == m_value )
        return false;

    m_value = value;

    if ( newval )
        *newval = GetValue();

    return true;
}
Beispiel #12
0
//Forwared here from CMirrorSurface
void CMirror::OnRenderScene( CCamera *camera ){
	_surface->Instances().clear();
	
	//No recursion yet...
	if( camera==_camera ) return;

	//frustum clipping.
	//Note: CModelSurface still clips itself - add enable/disable clipping for CModelSurface
	CBox bounds=RenderMatrix() * CBox( CVec3( -_width/2,-_height/2,0 ),CVec3( _width/2,_height/2,0 ) );
	if( !camera->RenderFrustum().Intersects( bounds ) ) return;
	
	const CMat4 &mir=RenderMatrix();
	const CMat4 &cam=camera->RenderMatrix();

	//put eye into mirror space
	CVec3 eye=-mir * cam.t.xyz();
	if( eye.z>0 ) return;

	//reflect
	eye.z=-eye.z;

	//projection matrix
	float znear=eye.z;
	float zfar=256.0f;
	float left=(-_width/2-eye.x),right=left+_width;
	float bottom=(-_height/2+eye.y),top=bottom+_height;
	CMat4 proj=CMat4::FrustumMatrix( left,right,bottom,top,znear,zfar );

	//camera matrix
	CMat4 mat;
	mat.i.x=-1;
	mat.k.z=-1;
	mat.t.xyz()=eye;
	mat=mir * mat;

	_camera->SetWorldMatrix( mat );
	_camera->SetProjectionMatrix( proj );
	
	CTexture *cb=App.Graphics()->ColorBuffer( 0 );
	App.Graphics()->SetColorBuffer( 0,Texture() );
	App.Scene()->RenderCamera( _camera );
	App.Graphics()->SetColorBuffer( 0,cb );
	
	_surface->Instances().push_back( mir );
}
Beispiel #13
0
static void	WriteCoords(std::wofstream &ofs)
{
	CBox box;
	GetWorldBox(box);

	if(!box.m_valid)
	{
		box = CBox(-100, -100, -50, 100, 100, 50);
	}
	else
	{
		while(box.Width() < 100){box.m_x[0] -= 5.0; box.m_x[3] += 5.0;}
		while(box.Height() < 100){box.m_x[1] -= 5.0; box.m_x[4] += 5.0;}
		box.m_x[2] -= 10.0;
	}

	ofs<<"toolpath.coords = Coords("<<box.MinX()<<", "<<box.MinY()<<", "<<box.MinZ()<<", "<<box.MaxX()<<", "<<box.MaxY()<<", "<<box.MaxZ()<<")\n";
}
///////////////////////////////////////////////////////////////
//
// CClientSpatialDatabaseImpl::FlushUpdateQueue
//
// Process all entities that have changed since the last call
//
///////////////////////////////////////////////////////////////
void CClientSpatialDatabaseImpl::FlushUpdateQueue ( void )
{
    std::map < CClientEntity*, int > updateQueueCopy = m_UpdateQueue;
    m_UpdateQueue.clear ();
    for ( std::map < CClientEntity*, int >::iterator it = updateQueueCopy.begin (); it != updateQueueCopy.end (); ++it )
    {
        CClientEntity* pEntity = it->first;

        // Get the new bounding box
        SEntityInfo newInfo;
        CSphere sphere = pEntity->GetWorldBoundingSphere ();
        newInfo.box = CBox ( sphere.vecPosition, fabsf ( sphere.fRadius ) );
        // Make everything 2D for now
        newInfo.box.vecMin.fZ = SPATIAL_2D_Z;
        newInfo.box.vecMax.fZ = SPATIAL_2D_Z;

        // Get previous info
        if ( SEntityInfo* pOldInfo = MapFind ( m_InfoMap, pEntity ) )
        {
            // Don't update if bounding box is the same
            if ( pOldInfo->box == newInfo.box )
                continue;

            // Remove old bounding box from tree
            m_Tree.Remove ( &pOldInfo->box.vecMin.fX, &pOldInfo->box.vecMax.fX, pEntity );
        }

        if ( !IsValidSphere ( sphere ) )
            continue;

        // Add new bounding box
        m_Tree.Insert( &newInfo.box.vecMin.fX, &newInfo.box.vecMax.fX, pEntity );

        // Update info map
        MapSet ( m_InfoMap, pEntity, newInfo );
    }
}
Beispiel #15
0
wxString wxGridCellBoolEditor::GetValue() const
{
  return ms_stringValues[CBox()->GetValue()];
}
int main(int argc, char** argv)
{
	int defw = 640;
	int defh = 480;
	if (argc == 3)
	{
		/*the program was run using 3 arguments
		argv[0] = name of the executable file
		argv[1] = screen width (as a string)
		argv[2] = screen height (as a string)
		*/
		defw = atoi(argv[1]);
		defh = atoi(argv[2]);
	}
	if (!al_init()) return 1; //exit if can't initialize allegro
	//initialize most stuff
	al_install_keyboard();
	al_init_primitives_addon();
	//run in a window
	al_set_new_display_flags(ALLEGRO_WINDOWED);

	//initialize our display and event queue
	ALLEGRO_DISPLAY* display = al_create_display(defw, defh);
	ALLEGRO_EVENT_QUEUE* eventq = al_create_event_queue();

	//this timer will tick once per frame
	ALLEGRO_TIMER* framet = al_create_timer(1.0 / 30.0); //30 frames per second
	al_start_timer(framet);

	//register the event sources so they send events to our queue
	al_register_event_source(eventq, al_get_display_event_source(display)); //display/window
	al_register_event_source(eventq, al_get_keyboard_event_source()); //keyboard
	al_register_event_source(eventq, al_get_timer_event_source(framet)); //fps timer

	//this box is our play field (covers the whole screen)
	CBox fieldbox(0, 0, defw, defh);

	//we setup the ball at the center of the screen with white color
	CBall ball(CBox(defw / 2 - 10, defh / 2 - 10, 20, 20), al_map_rgb(255, 255, 255));
	//we tell it to move to the left
	ball.setXYMovement(-5.0, 0.0);

	//we initialize our both players in an array
	CPlayer players[2] = {
		//red player on the left
		CPlayer(CBox(10, defh / 2 - 80 / 2, 20, 80), al_map_rgb(255, 0, 0)),
		//blue player on the right
		CPlayer(CBox(defw - 10 - 20, defh / 2 - 80 / 2, 20, 80), al_map_rgb(0, 0, 255)),
	};

	/*when this variable is set to true
	the program will quit the main loop
	and free the allocated resources
	before quitting */
	bool exit = false;
	while (!exit)
	{
		al_wait_for_event(eventq, NULL);
		ALLEGRO_EVENT ev;
		while (al_get_next_event(eventq, &ev))
		{
			if (ev.type == ALLEGRO_EVENT_TIMER)
			{
				if (ev.timer.source == framet)
				{
					//fill the screen with black
					al_clear_to_color(al_map_rgb(0, 0, 0));
					//move and draw our two players
					for (int i = 0; i<2; i++)
					{
						players[i].move(fieldbox);
						players[i].draw();
					}
					//move, collide and draw the ball
					switch (ball.move(fieldbox, players))
					{
					case 0:
						break;
					case 1:
						players[0].setScore(players[0].getScore() + 1);
						ball.setXYMovement(5.0, 0.0);
						break;
					case 2:
						players[1].setScore(players[1].getScore() + 1);
						ball.setXYMovement(-5.0, 0.0);
						break;
					}
					ball.draw();
					//show what we've drawn
					al_flip_display();
				}
			}
			else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
			{
				//quit if the user tries to close the window
				if (ev.display.source == display) exit = true;
			}
			else if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
			{
				//handle key presses
				switch (ev.keyboard.keycode)
				{
				case ALLEGRO_KEY_W:
					players[0].setYMovement(-3.0);
					break;
				case ALLEGRO_KEY_S:
					players[0].setYMovement(3.0);
					break;
				case ALLEGRO_KEY_UP:
					players[1].setYMovement(-3.0);
					break;
				case ALLEGRO_KEY_DOWN:
					players[1].setYMovement(3.0);
					break;
				case ALLEGRO_KEY_ESCAPE:
					exit = true;
					break;
				case ALLEGRO_EVENT_DISPLAY_CLOSE:
					exit = true;
					break;
				}
			}
			else if (ev.type == ALLEGRO_EVENT_KEY_UP)
			{
				int code = ev.keyboard.keycode;
				/*avoid clumsy movement making sure the released key corresponds with
				the moving direction*/
				if (code == ALLEGRO_KEY_W && players[0].getYMovement() < 0)
					players[0].setYMovement(0.0);
				else if (code == ALLEGRO_KEY_S && players[0].getYMovement() > 0)
					players[0].setYMovement(0.0);
				else if (code == ALLEGRO_KEY_UP && players[1].getYMovement() < 0)
					players[1].setYMovement(0.0);
				else if (code == ALLEGRO_KEY_DOWN && players[1].getYMovement() > 0)
					players[1].setYMovement(0.0);
			}
		}
	}
	al_destroy_event_queue(eventq);
	al_destroy_timer(framet);
	al_destroy_display(display);
}
Beispiel #17
0
void wxGridCellBoolEditor::StartingClick()
{
    CBox()->SetValue(!CBox()->GetValue());
}