Esempio n. 1
0
int main()
{
	while (1)
	{
		scanf("%s",inst);
		if (inst[0] == '8')
			break;
		pos = 0;
		int over = 0;
		A = B = 0;
		while (1)
		{
			switch (inst[pos])
			{
				case '0':command0();break;
				case '1':command1();break;
				case '2':command2();break;
				case '3':command3();break;
				case '4':command4();break;
				case '5':command5();break;
				case '6':command6();break;
				case '7':command7();break;
				case '8':over = 1;break;
				default:over = 1;break;
			}
			if (over || pos > 255)
				break;
		}
		printf("%s\n",inst);
	}
	return 0;
}
void TestPageCommands::testInsertPageCommand() // move of frames
{
    KWDocument document;
    KWPageInsertCommand command1(&document, 0);
    QCOMPARE(document.pageCount(), 0);
    QCOMPARE(document.frameSetCount(), 0);
    command1.redo();
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 0);

    KWFrameSet *fs = new KWFrameSet();
    MockShape *shape = new MockShape();
    KWFrame *frame = new KWFrame(shape, fs);
    Q_UNUSED(frame);
    document.addFrameSet(fs);
    QPointF startPos = shape->position();

    KWPageInsertCommand command2(&document, 0);
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    command2.redo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(command2.page().pageNumber(), 1);
    QCOMPARE(command1.page().pageNumber(), 2);
    QPointF newPos = shape->position();
    QCOMPARE(newPos, QPointF(0, command2.page().height()) + startPos); // it moved ;)

    KWPageInsertCommand command3(&document, 2);
    command3.redo();
    QCOMPARE(document.pageCount(), 3);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(newPos, shape->position()); // it has not moved from page 2

    command3.undo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(newPos, shape->position()); // it has not moved from page 2
    QCOMPARE(command2.page().pageNumber(), 1);
    QCOMPARE(command1.page().pageNumber(), 2);

    command2.undo();
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(command1.page().pageNumber(), 1);
    QCOMPARE(startPos, shape->position()); // it has been moved back

    command2.redo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(command2.page().pageNumber(), 1);
    QCOMPARE(command1.page().pageNumber(), 2);
    QCOMPARE(QPointF(0, command2.page().height()) + startPos, newPos); // it moved again ;)
}
void TestPageCommands::testInsertPageCommand3() // restore all properties
{
    KWDocument document;
    KWPageInsertCommand command1(&document, 0);
    command1.redo();

    KWPage page = command1.page();
    KWPageStyle style = page.pageStyle();
    style.setHasMainTextFrame(false);
    style.setFootnoteDistance(10);
    KoPageLayout layout;
    layout.width = 400;
    layout.height = 300;
    layout.leftMargin = 4;
    layout.rightMargin = 6;
    layout.topMargin = 7;
    layout.bottomMargin = 5;
    style.setPageLayout(layout);
    page.setPageStyle(style);

    KWPageInsertCommand command2(&document, 1); // append one page.
    command2.redo();

    QCOMPARE(command2.page().pageStyle(), style);
    QCOMPARE(command2.page().width(), 400.);

    // undo and redo, remember order is important
    command2.undo();
    command1.undo();
    command1.redo();
    command2.redo();

    QVERIFY(command1.page() != page);
    QCOMPARE(command1.page().pageNumber(), 1);
    KWPageStyle style2 = command1.page().pageStyle();
    QCOMPARE(style2, style);
    QCOMPARE(style2.hasMainTextFrame(), false);
    QCOMPARE(style2.footnoteDistance(), 10.);
    KoPageLayout layout2 = style2.pageLayout();
    QCOMPARE(layout2, layout);

    QCOMPARE(command2.page().pageStyle(), style);
    QCOMPARE(command2.page().width(), 400.);
}
int _tmain(int argc, _TCHAR* argv[])
{
    ActiveObjectEngine active_objevt_engine;

    std::unique_ptr<ICommand> command1(new SleepDelayCommand( 1000, &active_objevt_engine, 'A' ) );
    std::unique_ptr<ICommand> command2(new SleepDelayCommand( 5000, &active_objevt_engine, 'B' ) );
    std::unique_ptr<ICommand> command3( new SleepDelayCommand( 500, &active_objevt_engine, 'C' ) );
    std::unique_ptr<ICommand> command4(new SleepDelayCommand( 10, &active_objevt_engine, 'E' ) );
    std::unique_ptr<ICommand> command5(new SleepDelayCommand( 4500, &active_objevt_engine, 'D' ) );

    active_objevt_engine.AddCommand( std::move( command1 ) );
    active_objevt_engine.AddCommand( std::move( command2 ) );
    active_objevt_engine.AddCommand( std::move( command3 ) );
    active_objevt_engine.AddCommand( std::move( command4 ) );
    active_objevt_engine.AddCommand( std::move( command5 ) );
	
    active_objevt_engine.Run();
    return 0;
}
void TestPageCommands::testInsertPageCommand2() // auto remove of frames
{
    KWDocument document;
    KWFrameSet *fs = new KWFrameSet();
    document.addFrameSet(fs);
    KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet);
    document.addFrameSet(tfs);

    KWPageInsertCommand command1(&document, 0);
    command1.redo();

    MockShape *shape1 = new MockShape();
    new KWFrame(shape1, fs);

    MockShape *shape2 = new MockShape();
    shape2->setUserData(new KoTextShapeData());
    new KWTextFrame(shape2, tfs);

    KWPageInsertCommand command2(&document, 1); // append a page
    command2.redo();
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 2);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(tfs->frameCount(), 1);

    // add a new frame for the page we just created.
    MockShape *shape3 = new MockShape();
    QPointF position(30, command2.page().offsetInDocument());
    shape3->setPosition(position);
    new KWTextFrame(shape3, tfs);
    QCOMPARE(tfs->frameCount(), 2);

    command2.undo(); // remove the page again.
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 2);
    QCOMPARE(fs->frameCount(), 1);
    QCOMPARE(tfs->frameCount(), 1); // the text frame is an auto-generated one, so it should be removed.
}
Esempio n. 6
0
bool ETsumoDriver::drive()
{
#if 0 //臨時スイープ 調整中(まともに走りません><)
    K_THETADOT = 6.5F;
    K_PHIDOT = 25.0F;
    if (!mInitState) {
        if(mSearchPoint == 1){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_1; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_1;}
        if(mSearchPoint == 2){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_2; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_2;mGps.adjustDirection(mGps.getDirection() + 30);}
        if(mSearchPoint == 3){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_1; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_1 -150;mGps.adjustDirection(mGps.getDirection() + 30);}
        if(mSearchPoint == 4){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_2 + 150; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_2;}
        if(mSearchPoint == 5){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_1; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_1 -300;}
        if(mSearchPoint == 6){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_2 + 300; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_2;}
        if(mSearchPoint == 7){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_1; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_1 -450;}
        if(mSearchPoint == 8){mPoint.X = GPS_ETSUMO_SEARCH_X_SWEEP_2 + 450; mPoint.Y = GPS_ETSUMO_SEARCH_Y_SWEEP_2;}
        if(mSearchPoint > 8)mSearchPoint = 1;
        mTripodCoordinateTrace.setTargetCoordinate(mPoint);//
        mInitState = true;
        mIsArrived = false;
        mTripodCoordinateTrace.setAllowableError(30);
        mTripodCoordinateTrace.setForward(50);
        mTimeCounter = 0;
    }
    if (mTripodCoordinateTrace.isArrived())
    {
        mInitState = false;
        mTimeCounter = 0;
        mSearchPoint++;
        return 0;
    }
    mTripodCoordinateTrace.execute();
    return 0;
#endif
    
    
    
#if 0 //超信地旋回調査用
    gDoSonar = true;
    K_THETADOT = 6.5F;
    K_PHIDOT = 25.0F;
    if(mTimeCounter < 100000){
        VectorT<float> command(50, 0);//第一要素:進行速度、第二要素:旋回速度
        mActivator.run(command);//制御機器にセット
    }
    else{
        VectorT<float> command2(0, 100);//第一要素:進行速度、第二要素:旋回速度
        mActivator.run(command2);//制御機器にセット
    }
    mTimeCounter++;
    return 0;
#endif
    
#if 0 //超信地旋回調査用
    if (mState == ETsumoDriver::INIT) { // 初期化状態
        gDoSonar = true;
        if(gSonarIsDetected){
            mInitState = true;
            mState = ETsumoDriver::DOHYO_IN;
            updateTargetCoordinates();
            //mTargetX = mTargetTotalX;
            //mTargetY = mTargetTotalY;
            return 0;
        }
        K_THETADOT = 6.5F;
        K_PHIDOT = 20.0F;
        mTimeCounter++;
        
        if (!mInitState) {
            if(mSearchPoint == 1){mPoint.X = GPS_ETSUMO_SEARCH_X; mPoint.Y = GPS_ETSUMO_SEARCH_Y;}
            if(mSearchPoint == 2){mPoint.X = GPS_ETSUMO_SEARCH_X + 200; mPoint.Y = GPS_ETSUMO_SEARCH_Y -200;}
            if(mSearchPoint == 3){mPoint.X = GPS_ETSUMO_SEARCH_X + 400; mPoint.Y = GPS_ETSUMO_SEARCH_Y -400;}
            if(mSearchPoint == 4){mPoint.X = GPS_ETSUMO_SEARCH_X + 600; mPoint.Y = GPS_ETSUMO_SEARCH_Y -600;}
            mCoordinateTrace.setTargetCoordinate(mPoint);//
            mInitState = true;
            mIsArrived = false;
            mCoordinateTrace.setAllowableError(30);
            mCoordinateTrace.setForward(50);
            mTimeCounter = 0;
        }
        if (mCoordinateTrace.isArrived()) {mIsArrived = true; mTimeCounter = 0; mMyAngle = mGps.getDirection();}
        if(mIsArrived){
            if((mGps.getDirection() <= mMyAngle - 720) || (mGps.getDirection() >= mMyAngle +720)){
                mInitState = false;
                mTimeCounter = 0;
                mSearchPoint++;
                return 0;
            }
            else{
                if((mSearchPoint % 2) == 0 ){
                    VectorT<float> command1(0, 100);//第一要素:進行速度、第二要素:旋回速度
                    mActivator.run(command1);//制御機器にセット
                }
                else{
                    VectorT<float> command2(0, -100);//第一要素:進行速度、第二要素:旋回速度
                    mActivator.run(command2);//制御機器にセット
                }
            }
            return 0;
        }
        mCoordinateTrace.execute();
        return 0;
    }
#endif

    //試走会用ライントレース
    /*
    if (mState == ETsumoDriver::INIT) { // 初期化状態
        if (mInitState) {
            gDoSonar = false;
            K_THETADOT = 7.5F;
            K_PHIDOT = 25.0F;
            mLineTrace.setForward(100);
            mInitState = false;
        }
        mLineTrace.execute();
    }
    */
    
    if (mState == ETsumoDriver::INIT) { // 初期化状態
        gDoSonar = false;
        mTimeCounter = 0;
        mOrigK_THETADOT =  K_THETADOT; // 後で戻すために保存
        mOrigK_PHIDOT = K_PHIDOT; // 後で戻すために保存
        K_THETADOT = 6.5F;
        K_PHIDOT = 20.0F;
        mScanState = UNKNOWN;
        mLightSensor.setLamp(0);//試しにライトセンサOFF
        
        //状態遷移
        mInitState = true;
        mState = ETsumoDriver::PREPARE_SPOTSEARCH;
    }

    if (mState == ETsumoDriver::PREPARE_SPOTSEARCH) {
        if (mInitState) {
            gDoSonar = false;
            K_THETADOT = 6.5F;
            K_PHIDOT = 60.0F;
            mTimeCounter = 0;
            mCoordinateTrace.setTargetCoordinate(MakePoint(GPS_ETSUMO_SEARCH_X, GPS_ETSUMO_SEARCH_Y));// @todo要再設定
            mCoordinateTrace.setForward(50.0);
            mCoordinateTrace.setAllowableError(30);
            mInitState = false;
            mIsArrived = false;
        }
        // 移動完了
        if (mCoordinateTrace.isArrived()) {
            mInitState = true;
            //mState = ETsumoDriver::SWINGSEARCH;
            mState = ETsumoDriver::SPOTSEARCH;
        }
        mCoordinateTrace.execute();
    }
    
    
    if (mState == ETsumoDriver::SPOTSEARCH) {
        if (mInitState) {
            gDoSonar = false; // 
            K_PHIDOT = K_PHIDOT_FOR_MOVE;
            mTimeCounter = 0;
            mAngleTrace.setForward(0);
            mAngleTrace.setTargetAngle(360.0);
            mAngleTrace.setAllowableError(2.0); // 2度
            mInitState = false;
            mIsArrived = false;
            mSonarDetectCount = 0;
            mTargetTotalX = 0;
            mTargetTotalY = 0;
        }
        // 方向転換完了
        if (! mIsArrived && mAngleTrace.isArrived()) {
            K_PHIDOT = K_PHIDOT_FOR_SEARCH;
            gDoSonar = true;
            mIsArrived = true;
        }
        // 方向転換完了してからスポットサーチ開始
        if(mIsArrived && (mTimeCounter % 20 == 0) && (mTimeCounter >= 100)){
            if(gSonarIsDetected){
                mSonarDetectCount++;
                updateTargetCoordinates();
                if(SUMO_DEBUG) {mSpeaker.playTone(1000, 1, 10);}
            }
            else if(mTimeCounter % 100 == 0){
                float setangle = mGps.getDirection() - 100;//この数値は十分大きいため、調整不要のはず
                mAngleTrace.setTargetAngle(setangle);
            }
        }
        
        //スポットサーチ範囲内で探知成功!
        if(mSonarDetectCount >= 3){
            mInitState = true;
            mTargetX = mTargetTotalX / mSonarDetectCount;
            mTargetY = mTargetTotalY / mSonarDetectCount;
            mState = ETsumoDriver::DOHYO_IN;
        }
        //スポットサーチ範囲内にペットボトルが無いことを確認、スイングサーチへ移行
        else if((Gps::marge180(mGps.getDirection()) <= -90.0) && mIsArrived){
            mInitState = true;
            mState = ETsumoDriver::SPOTSEARCH_to_SWINGSEARCH;
        }
        mAngleTrace.execute();
    }
    
    if (mState == ETsumoDriver::SPOTSEARCH_to_SWINGSEARCH) {
        if (mInitState) {
            gDoSonar = false;
            K_PHIDOT = 60.0F;
            mTimeCounter = 0;
            mCoordinateTrace.setTargetCoordinate(MakePoint(GPS_ETSUMO_SEARCH_X + 200.0, GPS_ETSUMO_SEARCH_Y - 200.0));// @todo要再設定
            mCoordinateTrace.setForward(RIKISHI_FORWARD);
            mCoordinateTrace.setAllowableError(30);
            mInitState = false;
            mIsArrived = false;
        }
        // 移動完了
        if (mCoordinateTrace.isArrived()) {
            mInitState = true;
            mState = ETsumoDriver::SWINGSEARCH;
        }
        mCoordinateTrace.execute();
    }
        
    if (mState == ETsumoDriver::SWINGSEARCH) {
        if (mInitState) {
            gDoSonar = false;
            K_PHIDOT = K_PHIDOT_FOR_MOVE;
            mTimeCounter = 0;
            mSonarDetectCount = 0;
            mAngleTrace.setForward(0);
            mAngleTrace.setTargetAngle(480);
            //mAngleTrace.setTargetAngle(415);
            mAngleTrace.setAllowableError(2.0); // 2度
            mInitState = false;
            mIsArrived = false;
            mTargetTotalX = 0;
            mTargetTotalY = 0;
        }
        // 方向転換完了
        if (! mIsArrived && mAngleTrace.isArrived()) {
            mIsArrived = true;
            mTimeCounter = 0;
            K_PHIDOT = K_PHIDOT_FOR_SEARCH;
            gDoSonar = true; // ソナー起動
        }
        // 方向転換完了してからスイングサーチ開始
        if(mIsArrived && (mTimeCounter % 20 == 0)){
            if(gSonarIsDetected){
                mSonarDetectCount++;
                updateTargetCoordinates();
                if(SUMO_DEBUG) {mSpeaker.playTone(500, 1, 20);}
            }
            else if((mTimeCounter % 100 == 0) && (mTimeCounter > 100)){
                float setangle = mGps.getDirection() - 100;
                mAngleTrace.setTargetAngle(setangle);
            }
        }
        
        //スイングサーチ範囲内で探知成功!
        if(mSonarDetectCount >= 3){
            mInitState = true;
            mTargetX = mTargetTotalX / mSonarDetectCount;
            mTargetY = mTargetTotalY / mSonarDetectCount;
            mState = ETsumoDriver::DOHYO_IN;
        }
        mAngleTrace.execute();
    }
    
    if (mState == ETsumoDriver::DOHYO_IN) {
        if (mInitState) {
            mTimeCounter = 0;
            K_PHIDOT = 60.0F;
            mTargetAngle = calcTargetAngle(mTargetX, mTargetY);//ターゲットのアングルを-180〜180で返す
            if((mTargetAngle > -45) && (mTargetAngle < 135)){
                mCoordinateTrace.setTargetCoordinate(MakePoint(mTargetX - 300, mTargetY));
            }
            else{
                mCoordinateTrace.setTargetCoordinate(MakePoint(mTargetX, mTargetY + 300));
            }
            mCoordinateTrace.setForward(RIKISHI_FORWARD);
            mCoordinateTrace.setAllowableError(30);
            mInitState = false;
            mIsArrived = false;
            gDoSonar = false; 
        }
        // 移動完了
        if (! mIsArrived && mCoordinateTrace.isArrived()) {
            mInitState = true;
            mState = ETsumoDriver::HAKKE_READY;
        }
        mCoordinateTrace.execute();
    }
    
    
    if (mState == ETsumoDriver::HAKKE_READY) {
        if (mInitState) {
            gDoSonar = false; 
            mTimeCounter = 0;
            mAngleTrace.setForward(0);
            K_PHIDOT = K_PHIDOT_FOR_MOVE;
            mTargetAngle = calcTargetAngle(mTargetX, mTargetY);//ターゲットのアングルを-180〜180で返す
            if((mTargetAngle > -45) && (mTargetAngle < 135)){
                mAngleTrace.setTargetAngle(45);
            }
            else{
                mAngleTrace.setTargetAngle(-45);
            }            
            mAngleTrace.setAllowableError(2.0); // 2度
            mInitState = false;
            mIsArrived = false;
        }
        // 方向転換完了
        if (! mIsArrived && mAngleTrace.isArrived()) {
            mIsArrived = true;
            mTimeCounter = 0;
            K_PHIDOT = K_PHIDOT_FOR_SEARCH;
        }
        // 方向転換完了してから落ち着くまで待機
        if(mIsArrived && (mTimeCounter > 100)){
            mInitState = true;
            mState = ETsumoDriver::SCAN;
        }
        
        mAngleTrace.execute();
    }
    if (mState == ETsumoDriver::SCAN) {
        if (mInitState) {
            gDoSonar = true; // ソナー起動
            K_PHIDOT = K_PHIDOT_FOR_SEARCH;
            mTimeCounter = 0;
            mSonarDetectCount = 0;
            mFailScanCounter = 0;
            mTargetTotalX = 0;
            mTargetTotalY = 0;
            mAngleTrace.setForward(0);
            mInitState = false;
            mIsArrived = false;
            mScanState = SWINGRIGHT;
        }
        //最初は右回りにスキャン、ターゲットロスト後に左回りにスキャン
        if(mTimeCounter % 20 == 0){
            if(gSonarIsDetected){
                mFailScanCounter = 0; //検知したら検知失敗回数をリセット
                mSonarDetectCount++;
                updateTargetCoordinates();
                if(SUMO_DEBUG) {mSpeaker.playTone(1000, 1, 10);}
            }
            else{
                mFailScanCounter++;
                if(mFailScanCounter > 255){
                    mFailScanCounter = 255;//念のため
                }
            }
            //右回りにスキャン
            if((mTimeCounter % 100 == 0) && (mScanState == SWINGRIGHT)){
                float setangle = mGps.getDirection() - 100;
                mAngleTrace.setTargetAngle(setangle);
            }
            //左回りにスキャン
            else if((mTimeCounter % 100 == 0) && (mScanState == SWINGLEFT)){
                float setangle = mGps.getDirection() + 100;
                mAngleTrace.setTargetAngle(setangle);
            }
        }
        //ターゲットロスト後に状態遷移
        if((mFailScanCounter >= 10) && (mSonarDetectCount >= 2)){
            //右回りなら左回りへ状態遷移
            if(mScanState == SWINGRIGHT){
                mFailScanCounter = 0;
                mPrevSonarDetectCount = mSonarDetectCount; //右回りの時の検知回数を保存
                mSonarDetectCount = 0;                     //右回りの時の検知回数をクリア
                mTimeCounter = 0;
                mScanState = SWINGLEFT;
            }
            //
            else if(mScanState == SWINGLEFT){
                gDoSonar = false;
                mTimeCounter = 0;
                mTargetX = mTargetTotalX / (mSonarDetectCount + mPrevSonarDetectCount);
                mTargetY = mTargetTotalY / (mSonarDetectCount + mPrevSonarDetectCount);
                mInitState = true;
                mState = ETsumoDriver::NOKOTTA_GO;
            }
        }
        mAngleTrace.execute();
    }

    if (mState == ETsumoDriver::NOKOTTA_GO) {
        if (mInitState) {
            gDoSonar = false; //
            K_PHIDOT = 30.0F;
            mTimeCounter = 0;
            mAngleTrace.setForward(0);
            mTargetAngle = calcTargetAngle(mTargetX, mTargetY);//ターゲットのアングルを-180〜180で返す
            mAngleTrace.setTargetAngle(mTargetAngle + 0);//左右視力の違い?補正 @todo機体依存か要調査
            mAngleTrace.setAllowableError(1.0); // 1度
            mInitState = false;
            mIsArrived = false;
            mOshidashiFlag = false;
        }
        if (! mIsArrived) {
            mTargetAngle = calcTargetAngle(mTargetX, mTargetY);//精度向上のため、動的にターゲットアングルを更新する
            mAngleTrace.setTargetAngle(mTargetAngle + 0);//左右視力の違い?補正 @todo機体依存か要調査
        }
            
        // 方向転換完了
        if (! mIsArrived && mAngleTrace.isArrived()) {
            mIsArrived = true;
            mTimeCounter = 0;
        }
        //ゆっくり押し出し、時々張り手
        if(!mOshidashiFlag && mIsArrived && (mTimeCounter > 100)){
            mAngleTrace.setForward(OSHIDASHI_FORWARD);//@todoベストな値を要検証
        }
        //押し出し判定
        if((mGps.getXCoordinate() > (GPS_ETSUMO_SEARCH_X + 800)) || (mGps.getYCoordinate() < (GPS_ETSUMO_SEARCH_Y - 800))){//@todoベストな値を要検証
            mAngleTrace.setForward(-30);//判定が出たらゆっくり後退
            mTimeCounter = 0;
            mOshidashiFlag = true;
            mLightSensor.setLamp(1);//ライトセンサON
        }
        //そっと4秒ほど後退後状態遷移
        if(mOshidashiFlag && (mTimeCounter > 500)){    
            //mState = ETsumoDriver::KACHI_NANORI;
            //mInitState = true;
        }
        mAngleTrace.execute();
    }
    /*メモリが足りない?ためコメントアウト
    if (mState == ETsumoDriver::KACHI_NANORI) {
        if (mInitState) {
            gDoSonar = false;
            K_PHIDOT = 60.0F;
            mTimeCounter = 0;
            mCoordinateTrace.setTargetCoordinate(MakePoint(0, 0));
            mCoordinateTrace.setForward(30);
            mCoordinateTrace.setAllowableError(30);
            mInitState = false;
            mIsArrived = false;
        }
        // 移動完了
        if (mCoordinateTrace.isArrived()) {
            mInitState = true;
            mState = ETsumoDriver::SPOTSEARCH_to_SWINGSEARCH;
        }
        mCoordinateTrace.execute();
    }
    */
    mTimeCounter++;
    return 0;
}
void TestPageCommands::testPageStylePropertiesCommand() // basic properties change
{
    KWDocument document;
    KWPageManager *manager = document.pageManager();

    KWPageStyle style("pagestyle1");
    KoPageLayout oldLayout;
    oldLayout.format = KoPageFormat::IsoA4Size;
    oldLayout.width = 101;
    oldLayout.height = 102;
    oldLayout.leftMargin = -1;
    oldLayout.rightMargin = -1;
    oldLayout.pageEdge = 7;
    oldLayout.bindingSide = 13;
    style.setPageLayout(oldLayout);

    KoColumns oldColumns;
    oldColumns.count = 4;
    oldColumns.gapWidth = 21;
    style.setColumns(oldColumns);
    KWPage page1 = manager->appendPage(style);
    page1.setDirectionHint(KoText::LeftRightTopBottom);

    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.width(), 101.);
    QCOMPARE(page1.height(), 102.);
    QCOMPARE(page1.leftMargin(), 13.); // its a right-sided page
    QCOMPARE(page1.pageEdgeMargin(), 7.);
    QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
    QCOMPARE(page1.pageStyle().columns().count, 4);
    QCOMPARE(page1.pageSide(), KWPage::Right);

    // new ;)
    KWPageStyle style2("pagestyle2");
    KoPageLayout newLayout;
    newLayout.width = 401;
    newLayout.height = 405;
    newLayout.leftMargin = 11;
    newLayout.rightMargin = 18;
    newLayout.pageEdge = -1;
    newLayout.bindingSide = -1;
    style2.setPageLayout(newLayout);
    KoColumns newColumns;
    newColumns.count = 2;
    newColumns.columnData.append(ColumnDatum(1.0, 2.0, 1.0, 1.0, 25));
    newColumns.columnData.append(ColumnDatum(1.0, 1.0, 1.0, 1.0, 50));
    style2.setColumns(newColumns);
    style2.setDirection(KoText::RightLeftTopBottom);

    KWPageStylePropertiesCommand command1(&document, style, style2);

    // nothing changed before the redo
    QCOMPARE(page1.width(), 101.);
    QCOMPARE(page1.height(), 102.);
    QCOMPARE(page1.leftMargin(), 13.); // its a right-sided page
    QCOMPARE(page1.pageEdgeMargin(), 7.);
    QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);

    // redo
    command1.redo();
    QCOMPARE(page1.pageStyle().name(), QString("pagestyle1")); // name didn't change
    QCOMPARE(page1.width(), 401.);
    QCOMPARE(page1.height(), 405.);
    QCOMPARE(page1.leftMargin(), 11.);
    QCOMPARE(page1.pageEdgeMargin(), -1.); // its a right-sided page
    QCOMPARE(page1.pageStyle().direction(), KoText::RightLeftTopBottom);
    QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
    page1.setDirectionHint(KoText::InheritDirection); // reset to what the style says
    QCOMPARE(page1.directionHint(), KoText::RightLeftTopBottom);
    QCOMPARE(style.pageLayout().width, 401.); // style changed
    QCOMPARE(page1.pageStyle().columns().count, 2);
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);

    QCOMPARE(manager->pageCount(), 1);
    QVERIFY(manager->page(1).isValid());
    QVERIFY(!manager->page(2).isValid());

    KWPage page2 = manager->appendPage(style);
    QCOMPARE(manager->pageCount(), 2);
    QVERIFY(manager->page(1).isValid());
    QVERIFY(manager->page(2).isValid());
    QVERIFY(!manager->page(3).isValid());
    QCOMPARE(page2.pageNumber(), 2);
    QCOMPARE(page2.pageSide(), KWPage::Left);

    // undo
    command1.undo();
    QCOMPARE(page1.pageStyle().name(), QString("pagestyle1")); // name didn't change
    QCOMPARE(page1.width(), 101.);
    QCOMPARE(page1.height(), 102.);
    QCOMPARE(page1.leftMargin(), 13.);
    QCOMPARE(page1.directionHint(), KoText::AutoDirection);
    QCOMPARE(style.pageLayout().width, 101.);
    QCOMPARE(page1.pageStyle().columns().count, 4);
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);
    QCOMPARE(manager->pageCount(), 2);
    QVERIFY(manager->page(1).isValid());
    QVERIFY(manager->page(2).isValid());
    QVERIFY(!manager->page(3).isValid());
    QCOMPARE(page2.pageNumber(), 2);
    QCOMPARE(page2.pageSide(), KWPage::Left);
    QCOMPARE(page2.width(), 101.); // same style
    QCOMPARE(page2.height(), 102.);
    QCOMPARE(page2.leftMargin(), 7.);
    QCOMPARE(page2.directionHint(), KoText::AutoDirection);
}
void TestPageCommands::testRemovePageCommand() // move of frames
{
    KWDocument document;
    KWPageInsertCommand insertCommand(&document, 0);
    insertCommand.redo();

    KWFrameSet *fs = new KWFrameSet();
    MockShape *shape = new MockShape();
    KWFrame *frame = new KWFrame(shape, fs);
    Q_UNUSED(frame);
    document.addFrameSet(fs);
    KWPageInsertCommand insertCommand2(&document, 1);
    insertCommand2.redo();
    MockShape *shape2 = new MockShape();
    QPointF pos = QPointF(20, insertCommand2.page().offsetInDocument() + 10);
    shape2->setPosition(pos);
    KWFrame *frame2 = new KWFrame(shape2, fs);
    Q_UNUSED(frame2);
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 2);

    // remove page2
    KWPageRemoveCommand command1(&document, insertCommand2.page());
    command1.redo();

    QCOMPARE(insertCommand.page().pageNumber(), 1);
    QCOMPARE(insertCommand2.page().isValid(), false);

    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);

    QCOMPARE(shape2->position(), pos); // shapes are not deleted, just removed from the document

    command1.undo();
    QCOMPARE(insertCommand.page().pageNumber(), 1);
    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 2);

    QCOMPARE(shape2->position(), pos); // not moved.

    // remove page 1
    KWPageRemoveCommand command2(&document, insertCommand.page());
    command2.redo();

    QCOMPARE(insertCommand.page().isValid(), false);
    QCOMPARE(document.pageCount(), 1);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 1);

    QCOMPARE(shape->position(), QPointF(0,0));
    QCOMPARE(shape2->position(), QPointF(20, 10)); // moved!

    command2.undo();

    QCOMPARE(document.pageCount(), 2);
    QCOMPARE(document.frameSetCount(), 1);
    QCOMPARE(fs->frameCount(), 2);
    QCOMPARE(shape->position(), QPointF(0,0));
    QCOMPARE(shape2->position(), pos); // moved back!
}
Esempio n. 9
0
bool executeCommand(sqlite3 *db, const char *command)
{
    char **params;
    int paramsCount;
    int i;

    int from, to;
    double sum;

    (void)db;   // unused


    // parse command
    paramsCount = countWords(command);
    params = malloc(sizeof(char*) * paramsCount);
    for (i=0; i<paramsCount; i++)
        params[i] = getWord(command, i);            

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_HELP)))
        commandHelp();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_1)))
        command1();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_2)))
        command2();

    if ((paramsCount >= 4) && (!strcmp(params[0], COMMAND_TRANSF)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[3], "%lf", &sum);
        sscanf(params[2], "%i", &to);
        //transfer(db, from, to, sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
        credit(db, to, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_DEB)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_CRED)))
    {
        sscanf(params[1], "%i", &to);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0) return false;
        credit(db, to, sum);
    }

    if ((paramsCount >= 2) && (!strcmp(params[0], COMMAND_CHCK)))
    {
        sscanf(params[1], "%i", &to);
        checkAccount(db, to);
    }

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_UNDO)))
        undo(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADD)))
        createNewCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DEL)))
        deleteCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DELACC)))
        deleteAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADDACC)))
        addAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_COMMIT)))
        commit(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_SHOW)))
        showAll(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_LOGGER)))
        logger(db);

    for (i=0; i<paramsCount; i++)
        free(params[i]);
    free(params);

    return true;
}