示例#1
0
void EntityManager::createCar(char* path, btScalar &mass, btTransform &trans)
{	
	btScalar width = btScalar(10.0f);
	btScalar height = btScalar(2.5f);
	btScalar depth = btScalar(5.f);

	Car* car = new Car();
	car->carMass = mass;
	car->id = carList.size();

	car->initRenderObject(path);
	
	btCollisionShape* boxShape = sFactory.createBox(width, height, depth);

	car->initPhysicsObject(boxShape, mass, trans);

	if (carList.size() < 1)
		car->initObservers();

	addCar(car);

	Physics::Inst()->addRigidBody(*car);

	//phyEngine->addEntity(*car);
}
示例#2
0
World::World()
{
	r(-241, 4);
	solver.addRay(&ray);
	addCar(-240, 3);
	addBox(0,0,600,.5,true);
	// man.Initialize(-230, 3);
	// Body* b; Joint* j;
	// while (b = man.RegisterBodies())
		// solver.addBody(b);
	// while (j = man.RegisterJoints())
		// solver.addJoint(j);
	//initIK(-2350, 30);
	//solver.SetGravityFunc(gravity);
}
示例#3
0
TabDialog::TabDialog(QWidget *parent):QDialog(parent)
{
    readToFile();
    findWidget = new Find(this);
    addWidget = new Add(this);
    tabWidget = new QTabWidget;
    tabWidget->addTab(findWidget,tr("Поиск"));
    tabWidget->addTab(addWidget,tr("Добавить"));
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(tabWidget);
    setLayout(layout);

    connect(addWidget,SIGNAL(addCar(Car)),this,SLOT(pushData(Car)));
    connect(findWidget,SIGNAL(findClick()),this,SLOT(importContainerInfo()));
    connect(this,SIGNAL(infoToTable(int,QVector<Car>)),this,SLOT(findResult(int,QVector<Car>)));
    setWindowTitle(tr("Каталог автомобилей"));
}
示例#4
0
void Scene::updateCars() {
    std::vector<Car*> cars = world->getCars();
    std::set<Car*> carsSet(cars.begin(), cars.end());
    for (const auto &car : cars) {
        if (!carsItems.count(car)) {
            addCar(car);
        }
        Point<double> coordinates = car->getCoordinates();
        QGraphicsItem *rect = carsItems[car];
        rect->setPos(coordinates.toQPoint());
        rect->setRotation(qRadiansToDegrees(car->getDirection()));
    }
    std::vector<Car*> toRemoveCars;
    for (const auto &carItem : carsItems) {
        if (!carsSet.count(carItem.first)) {
            toRemoveCars.push_back(carItem.first);
        }
    }
    for (const auto &car : toRemoveCars) {
        removeItem(carsItems[car]);
        carsItems.erase(car);
    }
}
示例#5
0
int main(int argc, char * argv[])
{
    
    int choice = 0;
    int forRentEmpty = 1;
    int rentedEmpty = 1;
    int repairEmpty = 1;
    char * plate;
    //printType is either (a)vailable for rent, (b)rented, (c)in repair, or (e)mpty
    char printType = 'e';
    int mileage;
    int returnDate;
    int numOfDigits;
    int day;
    int month;
    double total = 0;
    double subTotal = 0;
    struct car * firstForRent = NULL;
    struct car * nextForRent = NULL;
    struct car * firstRented = NULL;
    struct car * nextRented = NULL;
    struct car * firstInRepair = NULL;
    struct car * nextInRepair = NULL;
    struct car * listChange = NULL;
    
    FILE * playlist;
    char * theString;
    
    char * theTypeToken;
    char theType;
    
    char line[BUFFER_SIZE];



/*Opens the file and strtoks each section of each line into the corresponding variable. For example, the bit of data that preceeds the first comma will be copied into mileage as an integer. The program then sorts each car into the appropriate list (available for rent, rented, and in repair)
 */
 
    if (argc != 2)
    {
        printf("Please specify a file\n");
        exit(1);
    }
    playlist = fopen(argv[1], "r+");
    if(playlist == NULL)
    {
        printf("Error opening file\n");
        exit(1);
    }
    while((fgets(line, sizeof(line), playlist))!=NULL)
    {
        theString = malloc(sizeof(char)*(strlen(line)+1));
        
        strcpy(theString, line);
        mileage = atoi(strtok(theString, ","));
        returnDate = atoi(strtok(NULL, ","));
        plate = strtok(NULL, ",");
        theTypeToken = strtok(NULL, ",");
        theType = theTypeToken[0];
        
        /* a = available for rent
         b = rented
         c = in repair
         */
        if((forRentEmpty == 1)&&(theType == 'a'))
        {
            firstForRent = addCar(mileage, returnDate, plate);
            forRentEmpty = 0;

        }
        else if((rentedEmpty == 1)&&(theType == 'b'))
        {
            firstRented = addCar(mileage, returnDate, plate);
            rentedEmpty = 0;
        }
        
        else if((repairEmpty == 1)&&(theType == 'c'))
        {
            firstInRepair = addCar(mileage, returnDate, plate);
            repairEmpty = 0;
        }
        
        else if((forRentEmpty == 0)&&(theType == 'a'))
        {
            nextForRent = addCar(mileage, returnDate, plate);
            firstForRent = orderByMileage(firstForRent, nextForRent);
        }
        else if((rentedEmpty == 0)&&(theType == 'b'))
        {
            nextRented = addCar(mileage, returnDate, plate);
            firstRented = orderByReturn(firstRented, nextRented);
        }
        else if((repairEmpty == 0)&&(theType == 'c'))
        {
            nextInRepair = addCar(mileage, returnDate, plate);
            firstInRepair = orderByMileage(firstInRepair, nextInRepair);
        }
        
    }


    
    printf("Hello.");
    while(choice != 7)
    {
        printf("\nPlease enter a transaction code (1-7) from below.\n");
        printf("(1)Add a new car to the available-for-rent list\n(2)Add a returned car to the available-for-rent list\n(3)Add a returned car to the repair list\n(4)Transfer a car from the repair list to the available-for-rent list\n(5)Rent the first available car\n(6)Print all the lists\n(7)Quit\n");
        /*The following ensures that the user selects an integer between 1 & 7, and executes accordingly*/
        choice = intCheck();
        while((choice!=1)&&(choice!=2)&&(choice!=3)&&(choice!=4)&&(choice!=5)&&(choice!=6)&&(choice!=7))
        {
            printf("Please selection from options 1 through 7\n");
            choice = intCheck();
        }
        /*For choice 1 the user inputs a plate and a mileage, and the information is stored into the available for rent list*/
        if(choice == 1)
        {
            returnDate = 0;
            printf("Please enter in a plate number\n");
            scanf("%s", plate);
            printf("Please enter a mileage\n");
            mileage = intCheck();
            
            if(forRentEmpty == 1)
            {
                firstForRent = addCar(mileage, returnDate, plate);
                forRentEmpty = 0;
                
            }
            else
            {
                nextForRent = addCar(mileage, returnDate, plate);
                firstForRent = orderByMileage(firstForRent, nextForRent);
            }
            printf("The new car with the plate %s was added to the available-for-rent list\n", plate);
        }
        /*Transfers a rented car to the available for rent list. The user enters a plate, the plate is searched for in the rented list, and removed if found. The information for the car with that plate is then entered into the available for rent list. The total and subtotal are calculated and the subtotal is printed*/
        else if(choice == 2)
        {
            if(firstRented == NULL)
            {
                printf("The rented list is empty. There are no cars to return\n");
            }
            else
            {
                printf("Please enter in a plate number\n");
                scanf("%s", plate);
                printf("Please enter a mileage\n");
                mileage = intCheck();
                
                
                listChange = removeFromList(&firstRented, plate);
                if(firstRented == NULL)
                {
                    rentedEmpty = 1;
                }
                
                if(listChange == NULL)
                {
                    printf("The plate does not exist in the rented list\n");
                }
                else if(forRentEmpty == 1)
                {
                    firstForRent = addCar(listChange->mileage, listChange->returnDate,listChange->plate);
                    firstForRent->mileage = mileage;
                    firstForRent->returnDate = 0;
                    forRentEmpty = 0;
                }
                else
                {
                    nextForRent = addCar(listChange->mileage, listChange->returnDate, listChange->plate);
                    nextForRent->mileage = mileage;
                    nextForRent->returnDate = 0;
                    firstForRent = orderByMileage(firstForRent, nextForRent);
                    
                }
                if(listChange != NULL)
                {
                    subTotal = transactionCalculator(mileage);
                    total = total + subTotal;
                    printf("The  car with the plate %s was move from the rented list to the available-for-rent list\n", plate);
                    printf("The total for your transaction is $%.2lf\n", subTotal);
                }
            }

        }
        /*Transfers a rented car to the repair list. The user enters a plate, the plate is searched for in the rented list, and removed if found. The information for the car with that plate is then entered into the available for rent list. The total and subtotal are calculated and the subtotal is printed*/
        else if(choice == 3)
        {
            if(firstRented == NULL)
            {
                printf("The rented list is empty. There are no cars to return\n");
            }
            else
            {
                printf("Please enter in a plate number\n");
                scanf("%s", plate);
                printf("Please enter a mileage\n");
                mileage = intCheck();

                
                listChange = removeFromList(&firstRented, plate);
                if(firstRented == NULL)
                {
                    rentedEmpty = 1;
                }
                
                if(listChange == NULL)
                {
                    printf("The plate does not exist in the rented list\n");
                }
                else if(repairEmpty == 1)
                {
                    firstInRepair = addCar(listChange->mileage, listChange->returnDate,listChange->plate);
                    firstInRepair->mileage = mileage;
                    firstInRepair->returnDate = 0;
                    repairEmpty = 0;
                }
                else
                {
                    nextInRepair = addCar(listChange->mileage, listChange->returnDate, listChange->plate);
                    nextInRepair->mileage = mileage;
                    nextInRepair->returnDate = 0;
                    firstInRepair = orderByMileage(firstInRepair, nextInRepair);
                    
                }
                if(listChange != NULL)
                {
                    subTotal = transactionCalculator(mileage);
                    total = total + subTotal;
                    printf("The  car with the plate %s was move from the rented list to the repair list\n", plate);
                    printf("The total for your transaction is $%.2lf\n", subTotal);
                }
                
            }


        }
        /*Transfers a car in the repair list to the available for rent list. The user enters a plate, the plate is searched for in the repair list, and removed if found. The information for the car with that plate is then entered into the available for rent list.*/
        else if(choice  == 4)
        {
            if(firstInRepair == NULL)
            {
                printf("The repair list is empty\n");
            }
            else
            {
                printf("Please enter a plate number\n");
                scanf("%s", plate);


                listChange = removeFromList(&firstInRepair, plate);
                if(firstInRepair == NULL)
                {
                    repairEmpty = 1;
                }

                if(listChange == NULL)
                {
                    printf("The plate does not exist in the repair list\n");
                }
                else if(forRentEmpty == 1)
                {
                    firstForRent = addCar(listChange->mileage, listChange->returnDate,listChange->plate);
                    forRentEmpty = 0;
                }
                else
                {
                    nextForRent = addCar(listChange->mileage, listChange->returnDate, listChange->plate);
                    firstForRent = orderByMileage(firstForRent, nextForRent);

                }
                if(listChange != NULL)
                {
                    printf("The  car with the plate %s was move from the repair list to the available-for-rent list\n", plate);
                }
            }


        }
        /*Transfers the car at the head of the available-for-rent list to the rented list. The user is prompted for the return date, which must have 6 digits and be in the form yymmdd. If the user enters a month or day-of-the-month which doesn't exist (ex. month 13), and error message pops up and the user is re-prompted*/
        else if(choice == 5)
        {
            if(firstForRent == NULL)
            {
                printf("There are no available cars for rent\n");
                
            }
            else
            {
                printf("Please enter a transaction date (yymmdd)\n");
                returnDate = intCheck();
                numOfDigits = floor(log10(abs(returnDate))) + 1;
                day = returnDate % 100;
                month = returnDate % 10000;
                month = month - day;
                while((numOfDigits != 6)||(month > 31000)||(month < 100)||(day > 31)||(day < 0 ))
                {
                    printf("Your input must be 6 digits long in the form of [yymmd]\nThe month must be between 01-12 and the day must be between 01-31\n");
                    returnDate = intCheck();
                    numOfDigits = floor(log10(abs(returnDate))) + 1;
                    day = returnDate % 100;
                    month = returnDate % 10000;
                    month = month - day;
                }
                printf("%d\n%d\n", day, month);

                firstForRent->returnDate = returnDate;
                listChange = removeFromList(&firstForRent, firstForRent->plate);
                
                if(firstForRent == NULL)
                {
                    forRentEmpty = 1;
                }

                if(rentedEmpty == 1)
                {
                    firstRented = addCar(listChange->mileage, listChange->returnDate,listChange->plate);
                    rentedEmpty = 0;
                    
                }
                else
                {
                    nextRented = addCar(listChange->mileage, listChange->returnDate, listChange->plate);
                    firstRented = orderByReturn(firstRented, nextRented);
                }
                if(listChange != NULL)
                {
                    printf("The car with the plate %s was move from the available-for-rent list to the rented list\n", plate);
                }
            }

            
        }
        /*Prints all the lists*/
        else if(choice == 6)
        {
            
            if(forRentEmpty == 0)
            {
                printf("\n\n**Now printing the available-to-rent list**\n");
                printList(firstForRent, printType, playlist);
            }
            else
            {
                printf("The available-to-rent list is empty\n");
            }
            if(rentedEmpty == 0)
            {
                printf("\n\n**Now printing the rented list**\n");
                printList(firstRented, printType, playlist);
            }
            else
            {
                printf("The rented list is empty\n");
            }
            if(repairEmpty == 0)
            {
                printf("\n\n**Now printing the repair list**\n");
                printList(firstInRepair, printType, playlist);
            }
            else
            {
                printf("The repair list is empty\n");
            }
        }

    }
    
/*Writes all the car list information back to the file*/
    printf("Your total comes to: $%.2lf\n", total);
    playlist = fopen(argv[1], "wt");

    if(forRentEmpty == 0)
    {
        printList(firstForRent, 'a', playlist);
    }
    if(rentedEmpty == 0)
    {
        printList(firstRented, 'b', playlist);
    }

    if(repairEmpty == 0)
    {
        printList(firstInRepair, 'c', playlist);
    }
    
    
    free(theString);
    if(forRentEmpty == 0)
    {
        freeList(firstForRent);
    }
    if(repairEmpty == 0)
    {
        freeList(firstInRepair);

    }
    if(rentedEmpty == 0)
    {
        freeList(firstRented);

    }
    return 0;
    
    fclose(playlist);

}
示例#6
0
MainWindow::MainWindow(QWidget *parent,Qt::WindowFlags flags):QMainWindow(parent,flags){
	
	setAcceptDrops(true);	// 讓拖曳可以實現
	
	this->setWindowTitle("HiTSim");

	// 建立主畫面
	CentralWidget *centralwidget = new CentralWidget(this);

	this->setCentralWidget(centralwidget);

	// 建立工具列 - start
	// 建立工具列 - 建立第一個選單項目File - start
	QMenu *fileMenu = new QMenu("&File",this);
	QAction *fileAction = new QAction("Open..",fileMenu);
	fileAction->setEnabled(false);
	// 快捷鍵 Ctrl+O:當焦點在選單時,ctrl+o才會有效果,且下面兩行在一起才會有效果
	fileAction->setShortcut(Qt::CTRL + Qt::Key_O);
	fileMenu->addAction(fileAction);
	
	fileAction = new QAction("Save",fileMenu);
	fileAction->setEnabled(false);
	fileMenu->addAction(fileAction);

	// 快捷鍵 Ctrl+X,動作連接至 QApplication 的 quit()

	// 建立分格線
	fileMenu->addSeparator();
	
	fileMenu->addAction("Close",this,SLOT(close()),Qt::CTRL + Qt::Key_X);
	// 把建立好的選單加入主畫面中
	this->menuBar()->addMenu(fileMenu);
	// 建立工具列 - 建立第一個選單項目File - end
	// 建立工具列 - 建立第二個選單項目About - start
	QMenu *aboutMenu = new QMenu("&About");
	aboutMenu->addAction("About Qt",this,SLOT(aboutQt()));
	aboutMenu->addAction("About HiTSim",this,SLOT(aboutHiTSim()));
	this->menuBar()->addMenu(aboutMenu);
	// 建立工具列 - 建立第二個選單項目About - end
	// 建立建立工具列 - end
	
	// 建立工具列 - start
	QToolBar *toolBar = new QToolBar("QToolBar");
	QAction *toolBarAction = new QAction(QIcon(":open.png"),"open",toolBar);
	toolBarAction->setEnabled(false);	// 設定成按扭不能按,因為,還沒有功能
	toolBar->addAction(toolBarAction);
	toolBarAction = new QAction(QIcon(":icon_save"),"save",toolBar);
	toolBarAction->setEnabled(false);	// 設定成不能按,因為功能還沒有做好
	toolBar->addAction(toolBarAction);
	toolBar->addAction(QIcon(":/icon_clock.jpg"),"addCar",centralwidget,SLOT(addCar()));
	toolBar->addSeparator();
	toolBar->addAction(QIcon(":/icon_close.jpg"),"close",this,SLOT(close()));
	this->addToolBar(toolBar);
	// 建立工具列 - end
	
	// 建立狀態列 - start
	QStatusBar *statusBar = this->statusBar();
	statusBar->showMessage("Status here...");
	// 建立狀態列 - end
	
	// 建立停駐元件 - start
	QDockWidget *dockWidget = new QDockWidget("QDockWidget");
	QLabel *label = new QLabel(dockWidget);
	label->setPixmap(QPixmap(":/caterpillar.jpg"));
	dockWidget->setWidget(label);

	this->addDockWidget(Qt::RightDockWidgetArea,dockWidget);
	// 建立停駐元件 - end
	
	// 設定最大化 - start
	showMaximized();
	// 設定最大化 - end
}
示例#7
0
void Scene::addCars() {
    std::vector<Car*> cars = world->getCars();
    for (const auto &car : cars) {
        addCar(car);
    }
}