예제 #1
0
LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
{
    if( aComponent == NULL )
        return NULL;

    // Conflict detection: See if already existing aliases exist,
    // and if yes, ask user for continue or abort
    // Special case: if the library is the library cache of the project,
    // old aliases are always removed to avoid conflict,
    //      and user is not prompted )
    if( Conflicts( aComponent ) && !IsCache() )
    {
        wxFAIL_MSG( wxT( "Cannot add component <" ) + aComponent->GetName() +
                    wxT( "> to library <" ) + GetName() + wxT( "> due to name conflict." ) );
        return NULL;
    }


    LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this );

    for( size_t i = 0; i < newCmp->m_aliases.size(); i++ )
    {
        wxString aliasname = newCmp->m_aliases[i]->GetName();
        LIB_ALIAS* alias = FindAlias( aliasname );

        if( alias != NULL )
            RemoveEntry( alias );

        aliases[ aliasname ] = newCmp->m_aliases[i];
    }

    isModified = true;

    return newCmp;
}
예제 #2
0
파일: Rect.cpp 프로젝트: reverant/Tangram
ActualMoveInfo Rect::Move(int x,int y, Tan** tans){
    //jesli po przesuniêciu obiekt nie mieœci³by siê na ekranie zmniejszam iloœæ o któr¹ przesunê
    if(xmin+x < 0 || xmax+x > WIDTH){
        x = xmin+x<0 ? -xmin : WIDTH-xmax;
    }
    if(ymin+y < 0 || ymax+y > HEIGHT){
        y = ymin+y<0 ? -ymin : HEIGHT-ymax;
    }
    //tworzê testowy przesuniêty tan i jeœli nie koliduje on z innymi tanami to przesuwam docelowy tan
    Rect *rect=new Rect(wxPoint(points[0].x+x,points[0].y+y),
                        wxPoint(points[1].x+x,points[1].y+y),
                        wxPoint(points[2].x+x,points[2].y+y),
                        wxPoint(points[3].x+x,points[3].y+y));
    if(type==1) rect->type=3;
    if(!Conflicts(rect,tans)){
        xmin+=x;
        xmax+=x;
        ymin+=y;
        ymax+=y;
        for(int i=0;i<size;i++){
            points[i].x+=x;  
            points[i].y+=y;    
        } 
        //zwracam obiekt z informacj¹ o tym o ile przesun¹³ siê tan
        return ActualMoveInfo(x,y);
    }
    delete rect;
    //zwracam obiekt z informacj¹ o tym o ile przesun¹³ siê tan - przesuniecie wynosi 0 bo wystapil konflikt
    return ActualMoveInfo(0,0);
}
예제 #3
0
void Rect::Mirroring(Tan** tans) {   
    Vector vec[4];
    
    vec[0].Set(start_vectors[0].GetX(),start_vectors[2].GetY());
    vec[1].Set(start_vectors[1].GetX(),start_vectors[3].GetY());
    vec[2].Set(start_vectors[2].GetX(),start_vectors[0].GetY());
    vec[3].Set(start_vectors[3].GetX(),start_vectors[1].GetY());
    
    wxPoint temp_point;
    Vector temp_vectors[4];
    
    for(int j=0;j<GetSize();j++){
        temp_vectors[j] = matrix*vec[j];
        start_vectors[j] = vec[j];
        temp_point.x = temp_vectors[j].GetX();
        temp_point.y = temp_vectors[j].GetY();
        SetP(j+1,temp_point);
    }   
    
    if(Conflicts(this,tans)) 
    {
        vec[0].Set(start_vectors[0].GetX(),start_vectors[2].GetY());
        vec[1].Set(start_vectors[1].GetX(),start_vectors[3].GetY());
        vec[2].Set(start_vectors[2].GetX(),start_vectors[0].GetY());
        vec[3].Set(start_vectors[3].GetX(),start_vectors[1].GetY());
        
        wxPoint temp_point;
        Vector temp_vectors[4];
        
        for(int j=0;j<GetSize();j++){
            temp_vectors[j] = matrix*vec[j];
            start_vectors[j] = vec[j];
            temp_point.x = temp_vectors[j].GetX();
            temp_point.y = temp_vectors[j].GetY();
            SetP(j+1,temp_point);
        }   
    }

}
예제 #4
0
void BPMiniGame_ShortCircuitSudoku::GenerateGrid() {
	Sudoku.Clear();
	SudokuSquare* Squares[81];
	
	for (int i = 0; i < 81; ++i) {
		Squares[i] = new SudokuSquare();
	}
	
	BPList<int>* Available[81];
	int squarecounter = 0;
	
	for (int x = 0; x <= 81 - 1; x++) {
		Available[x] = new BPList<int>();
		for (int i = 1; i <= 9; i++) {
			Available[x]->Add(i);
		}
	}
	

	while (!(squarecounter == 81)) {
	Beginning:
		int i = TheGame->RandomRange(0, Available[squarecounter]->Count - 1);
		if (!(Available[squarecounter]->Count == 0)) { // we may need to start again with this square?
			int z = (*Available[squarecounter])[i];
			SudokuSquare* item = Item(squarecounter, z);
			if (Conflicts(Squares, item) == false) {
				// this number is good!
				SAFE_DELETE(Squares[squarecounter]);
				Squares[squarecounter] = item;
				Available[squarecounter]->RemoveAt(i);
				squarecounter += 1;
			} else {
				// number is no good - try again
				SAFE_DELETE(item);
				Available[squarecounter]->RemoveAt(i);
				goto Beginning; // goto! eek! Jump back to the start
			}
		} else {
			// reset the current square
			for (int y = 1; y <= 9; y++) {
				Available[squarecounter]->Add(y);
			}
			
			// jump back to the start
			SAFE_DELETE(Squares[squarecounter - 1]);
			Squares[squarecounter - 1] = new SudokuSquare();
			squarecounter -= 1;
			goto Beginning;
		}
	}
	
	// all done - allocate all the squares in the grid
	for (int j = 0; j < 81; j++) {
		ostringstream str;
		str << Squares[j]->Value;
		TheGame->AllocString(&Squares[j]->sfcStrValue, str.str().c_str(), NORMAL, 24, 24, CENTRED);
		Sudoku.Add(Squares[j]);
	}

	for (int i = 0; i < 81; ++i) {
		SAFE_DELETE(Available[i]);
	}
}