Пример #1
0
void CChooseColorDlg::OnBnClickedButtonDelete()
{
    POSITION pos = m_listColor.GetFirstSelectedItemPosition();
    if (pos == NULL)
    {
        ERROR_MESSAGEBOX("Please select items you want to remove");
        return;
    }
    std::vector<int> selArray;
    while (pos != NULL)
    {
        int nSel = m_listColor.GetNextSelectedItem(pos);
        selArray.push_back(nSel);
    }
    std::vector<int>::reverse_iterator ite = selArray.rbegin();
    while (ite != selArray.rend())
    {
        CString strText = m_listColor.GetItemText(*ite, 0);
        std::map<tstring, COLORREF>::iterator iteColor = m_colorMap.find(strText.GetBuffer(strText.GetLength()));
        if (iteColor != m_colorMap.end())
            m_colorMap.erase(iteColor);
        m_listColor.DeleteItem(*ite);
        ++ite;
    }
}
void ManagementTex::pushTex(
		unsigned int				texID,
		ID3D11ShaderResourceView*	srv)
{
	/*Create new Tex-object*/
	Tex* newTex = new Tex(texID, srv);

	texs_.push_back(newTex);
	unsigned int texsIndex = texs_.size() - 1;

	/*Map index of pushed back element to texture ID*/
	std::pair<
		std::map<unsigned int, unsigned int>::iterator,
		bool> ret;
	ret = texIDtoIndex_.insert(
		std::pair<unsigned int, unsigned int>(texID, texsIndex));

	if(!ret.second)
	{ //Element already exists in vector
		std::string errorMsg = 
			"TextureID "									+ 
			uintToString(texID)								+ 
			" already exists in TexManagement under Index " + 
			uintToString(texsIndex)							+ 
			".";
		ERROR_MESSAGEBOX(errorMsg);
	}
}
HRESULT ManagementTex::handleTexDesc(
	TexDesc*		texDesc,
	ID3D11Device*	device)
{
	HRESULT hr = S_OK;

	std::string	path = texDesc->getPath() + texDesc->getHeader().texPath_;
	std::vector<TexDescTex>	texDescs = texDesc->getTexDescs();

	unsigned int	texID;
	std::string		texFileName;
	for(unsigned int i = 0; i < texDescs.size(); i++)
	{
		texID		= texDescs.at(i).id_;
		texFileName	= texDescs.at(i).fileName_;

		hr = createTex(
			texID,
			path,
			texFileName,
			device);
		if(FAILED(hr))
		{
			ERROR_MESSAGEBOX("ManagementTex::handleTexDesc Could not load texture: " + texFileName);
		}
	}

	return hr;
}
void PlayerPhysicsObject::handleInput(float delta)
{
    std::vector<int> playerAttributes = itrPhysics_3.ownerAt(attributeIndex_)->getAttributes(ATTRIBUTE_PLAYER);
    if(playerAttributes.size() > 1)
    {
        ERROR_MESSAGEBOX("More than one controller for one player. Not tested.")
    }
    for(unsigned int i=0; i<playerAttributes.size(); i++)
    {
        AttributePtr<Attribute_Player> ptr_player = ptr_player = itrPlayer.at(playerAttributes.at(i));
        AttributePtr<Attribute_Input> ptr_input = ptr_player->ptr_input;
        AttributePtr<Attribute_Health> health = ptr_player->ptr_health;
        if(health->health <= 0)
        {
            continue;
        }

        //--------------------------------------------------------------------------------------
        //Look and move
        //--------------------------------------------------------------------------------------
        yaw_ += ptr_input->rotation.x;
        btVector3 move = ptr_player->currentSpeed*btVector3(ptr_input->position.x, 0, ptr_input->position.y);

        //lower player speed when recently damaged
        if(ptr_player->timeSinceLastDamageTaken < 1.0f)
        {
            move *= 0.75f;
        }

        //Move player
        move = move.rotate(btVector3(0,1,0),yaw_);
        move = btVector3(move.x(), getLinearVelocity().y(), move.z());
        setLinearVelocity(move);

        //Rotate player
        btTransform world;
        world = getWorldTransform();
        world.setRotation(btQuaternion(yaw_,0,0));
        setWorldTransform(world);

        //Jetpack
        if(ptr_player->jetpack)
        {
            float jetpackPower = -getGravity().y()*1.5f;
            world = getWorldTransform();
            btVector3 velocity = getLinearVelocity();
            if(world.getOrigin().y() < 18.0f)
            {
                setLinearVelocity(btVector3(move.x(), velocity.y()+jetpackPower*delta, move.z()));
            }
        }
        else if(ptr_input->jump && ptr_player->hovering) //Jump
        {
            float jumpPower = 600.0f;
            applyCentralImpulse(btVector3(0.0f, jumpPower, 0.0f));
            //applyCentralForce(btVector3(0.0f, jumpPower, 0.0f));
        }
    }
}
Пример #5
0
void CChooseColorDlg::OnBnClickedButtonAdd()
{
    UpdateData(TRUE);
    if (m_strCondition.IsEmpty())
    {
        ERROR_MESSAGEBOX("The filed 'Contain what' cannot be empty.");
        return;
    }

    tstring strCondition = m_strCondition.GetBuffer(m_strCondition.GetLength());
    if (m_colorMap.find(strCondition) != m_colorMap.end())
    {
        ERROR_MESSAGEBOX("This condition has already existed.");
        return;
    }
    m_colorMap[strCondition] = m_colorContorl.GetColor();
    m_listColor.InsertItem(m_listColor.GetItemCount(), m_strCondition);
}
Пример #6
0
bool LoaderFbx::createFbxScene()
{
	bool success = true;

	fbxScene_ = FbxScene::Create(fbxManager_, "Scene 1");
	if(!fbxScene_)
	{
		success = false;
		ERROR_MESSAGEBOX("LoaderFbx::createFbxScene | fbxScene_ could not be created");
	}
	return success;
}
Пример #7
0
void CLogAnalyzerView::OnEditLocatelogtrace()
{
    if (m_logger->GetActiveUISetting().isNull())
    {
        ERROR_MESSAGEBOX("CLogAnalyseDlg::OnQuickLocatethislineinnotepadd : UI Setting has incorrect info.");
        return;
    }
    //Get the selected component name
    tstring strText(m_strSelComponent.GetBuffer(m_strSelComponent.GetLength())); 
    //Get the selected trace log

    const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents();
    std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strText);
    if (ite != components.end())
    {
        //Search trace log
        const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs();
        TCHAR itemText[512] = {0};
        POSITION pt = m_traceList.GetFirstSelectedItemPosition();
        int nSelIndex = m_traceList.GetNextSelectedItem(pt);
        CString strLine = m_traceList.GetItemText(nSelIndex, 0);
        int nLine = Poco::NumberParser::parse(strLine.GetBuffer(strLine.GetLength()));

        for (int i = 0; i < traceLogs.size(); ++i)
        {
            if (nLine == traceLogs.at(i)->m_nLine)
            {
                std::vector<tstring> args;
                itoa(traceLogs.at(i)->m_nLine, itemText, 10);
                tstring strCommandLine = m_logger->GetActiveUISetting()->GetNodepadPath();
                strCommandLine += " -n";
                strCommandLine += itemText;
                strCommandLine += " \"";
                strCommandLine += m_logger->GetFileName();
                strCommandLine += "\"";
                Poco::Process::launch(strCommandLine, args);
                break;
            }
        }
    }
}
bool GameManager::init(HWND windowHandle, HWND parentWindowHandle)
{
	// Detect memory leaks
#if defined(DEBUG) || defined(_DEBUG)
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	entityManager_ = new EntityManager();

	//Initialize components
	componentManager_ = new ComponentManager();
	if(!componentManager_->init(windowHandle, parentWindowHandle))
	{
		ERROR_MESSAGEBOX("Component manager failed to init");
		return false;
	}

	//SEND_EVENT(&Event_StartDeathmatch(5));

	return true;
}
Пример #9
0
bool LoaderFbx::createFbxManager()
{
	bool success = true;

	fbxManager_ = FbxManager::Create();
	if(!fbxManager_)
	{
		success = false;
		ERROR_MESSAGEBOX("LoaderFbx::createFbxManager | fbxManager_ could not be created!");
	}
	else
	{
		FbxIOSettings* fbxIOSettings = FbxIOSettings::Create(fbxManager_, IOSROOT);
		fbxManager_->SetIOSettings(fbxIOSettings);

		FbxString path = FbxGetApplicationDirectory();
		fbxManager_->LoadPluginsDirectory(path.Buffer());
	}

	return success;
}
Пример #10
0
bool PhysicsObject::init(unsigned int attributeIndex, short collisionFilterGroup)
{
	if(attributeIndex < 0)
	{
		return false;
	}
	attributeIndex_ = attributeIndex;
	collisionFilterGroup_ = collisionFilterGroup;

	//Get the init data from a physics attribute
	AttributePtr<Attribute_Physics> ptr_physics = itrPhysics_.at(attributeIndex);
	btScalar mass = static_cast<btScalar>(ptr_physics->mass);

	//Resolve mass, local inertia of the collision shape, and also the collision shape itself.
	btCollisionShape* collisionShape = subClassSpecificCollisionShape();
	if(collisionShape != nullptr)
	{
		setCollisionShape(collisionShape);
	}
	else
	{
		ERROR_MESSAGEBOX("Error in PhysicsObject::init. Expected collision shape pointer unexpectedly set to nullptr. Using default shape instead.");
		setCollisionShape(CollisionShapes::Instance()->getDefaultShape());
	}
	
	btVector3 localInertia = subClassCalculateLocalInertiaHook(mass);
	setMassProps(mass, localInertia); //Set inverse mass and inverse local inertia
	updateInertiaTensor();
	if((getCollisionFlags() & btCollisionObject::CF_STATIC_OBJECT))
	{
		btTransform world;

		AttributePtr<Attribute_Spatial> ptr_spatial = itrPhysics_.at(attributeIndex_)->ptr_spatial;
		AttributePtr<Attribute_Position> ptr_position = ptr_spatial->ptr_position;
 		world.setOrigin(convert(ptr_position->position));
		world.setRotation(convert(ptr_spatial->rotation));
		setWorldTransform(world);  //Static physics objects: transform once
	}
	else
	{
		//Non-static physics objects: let a derived btMotionState handle transforms.
		MotionState* customMotionState = new MotionState(attributeIndex);
		setMotionState(customMotionState);

		setAngularVelocity(btVector3(ptr_physics->angularVelocity.x,
										ptr_physics->angularVelocity.y,
										ptr_physics->angularVelocity.z));
		setLinearVelocity(btVector3(ptr_physics->linearVelocity.x,
										ptr_physics->linearVelocity.y,
										ptr_physics->linearVelocity.z));
		//Gravity is set after "addRigidBody" for non-static physics objects
	}

	if(ptr_physics->collisionResponse)
	{
		setCollisionFlags(getCollisionFlags() & ~CF_NO_CONTACT_RESPONSE); //Activate collision response
	}
	else
	{
		setCollisionFlags(getCollisionFlags() | CF_NO_CONTACT_RESPONSE); //Deactivate collision response
	}
	
	return subClassSpecificInitHook();
}
void PhysicsComponent::synchronizeWithAttributes(AttributePtr<Attribute_Physics> ptr_physics, int physicsAttributeIndex)
{
	//Also refer to PhysicsComponent::onEvent, handling of EVENT_ATTRIBUTE_UPDATED

	//Checks if new physics attributes were created since last call to this function
	if(physicsAttributeIndex >= physicsObjects_->size())
	{
		physicsObjects_->push_back(nullptr);
	}
	//Synchronize physics attributes with internal PhysicsObjects
	if(ptr_physics->reloadDataIntoBulletPhysics) //If something has changed in the physics attribute
	{
		//If the PhysicsObjects already exists, it needs to be removed to safely reset all of its internal Bullet Physics values
		if(physicsObjects_->at(physicsAttributeIndex) != nullptr)
		{
			dynamicsWorld_->removeRigidBody(physicsObjects_->at(physicsAttributeIndex));
			delete physicsObjects_->at(physicsAttributeIndex);
		}
		// Determine type of PhysicsObject to create and add to the Bullet Physics world
		switch(ptr_physics->collisionFilterGroup)
		{
		default:
			physicsObjects_->at(physicsAttributeIndex) = new PhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::WORLD:
			physicsObjects_->at(physicsAttributeIndex) = new WorldPhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::PLAYER:
			physicsObjects_->at(physicsAttributeIndex) = new PlayerPhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::PROJECTILE:
			physicsObjects_->at(physicsAttributeIndex) = new ProjectilePhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::EXPLOSIONSPHERE:
			physicsObjects_->at(physicsAttributeIndex) = new ExplosionSpherePhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::PICKUPABLE:
			physicsObjects_->at(physicsAttributeIndex) = new PickupablePhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::PROP:
			physicsObjects_->at(physicsAttributeIndex) = new PropPhysicsObject();
			break;
		case XKILL_Enums::PhysicsAttributeType::EVERYTHING:
			ERROR_MESSAGEBOX("Error: Attribute_Physics should not have EVERYTHING as collisionFilterGroup");
			break;
		}

		if(physicsObjects_ != nullptr)
		{
			if(physicsObjects_->at(physicsAttributeIndex)->init(physicsAttributeIndex, ptr_physics->collisionFilterGroup) == true)
			{
				dynamicsWorld_->addRigidBody(physicsObjects_->at(physicsAttributeIndex), ptr_physics->collisionFilterGroup, ptr_physics->collisionFilterMask);

				//Per object gravity must be set after "btDiscreteDynamicsWorld::addRigidBody"
				if(!physicsObjects_->at(physicsAttributeIndex)->isStaticOrKinematicObject())
				{
					physicsObjects_->at(physicsAttributeIndex)->setGravity(btVector3(ptr_physics->gravity.x, ptr_physics->gravity.y, ptr_physics->gravity.z));
				}

				ptr_physics->reloadDataIntoBulletPhysics = false;
			}
			else
			{
				ERROR_MESSAGEBOX("-->Error initializing PhysicsObject. PhysicsComponent::synchronizeWithAttributes failed");
			}
		}
	}
}
void PhysicsComponent::onEvent(Event* e)
{
	EventType type = e->getType();
	switch(type)
	{
	case EVENT_ATTRIBUTE_UPDATED: //Removes physics objects when the corresponding physics attribute is removed
	{
		Event_AttributeUpdated* attributeUpdated = static_cast<Event_AttributeUpdated*>(e);
		int attributeIndex = attributeUpdated->index;
		if(attributeUpdated->attributeEnum == ATTRIBUTE_PHYSICS)
		{
			if(attributeUpdated->isDeleted)
			{
				if(attributeIndex < physicsObjects_->size() && physicsObjects_->at(attributeIndex) != nullptr)
				{
  					dynamicsWorld_->removeRigidBody(physicsObjects_->at(attributeIndex));
					delete physicsObjects_->at(attributeIndex);
					physicsObjects_->at(attributeIndex) = nullptr;
				}
				else
				{
					DEBUGPRINT("Mismatch when synchronizing deletion of physics objects with physics attributes");
				}
			}
			else if(attributeUpdated->isCreated)
			{
			}
			else
			{
				itrPhysics.at(attributeIndex)->reloadDataIntoBulletPhysics = true;
			}
		}
		/*else if(attributeUpdated->attributeEnum == ATTRIBUTE_CAMERA)
		{
			if(attributeUpdated->isDeleted)
			{
  				dynamicsWorld_->removeRigidBody(frustumPhysicsObjects_->at(attributeIndex));
				delete frustumPhysicsObjects_->at(attributeIndex);
				frustumPhysicsObjects_->at(attributeIndex) = nullptr;
			}
		}*/
		break;
	}
	case EVENT_MODIFY_PHYSICS_OBJECT:
	{
		Event_ModifyPhysicsObject* modifyPhysicsObject = static_cast<Event_ModifyPhysicsObject*>(e);

		int physicsAttributeIndex = modifyPhysicsObject->ptr_physics.index();
		if(physicsAttributeIndex < physicsObjects_->size() && physicsAttributeIndex > -1)
		{
			PhysicsObject* physicsObject = physicsObjects_->at(physicsAttributeIndex);
			if(physicsObject != NULL)
			{
				//Cast void pointer sent in Event_ModifyPhysicsObject to its expected data type and modify physics object accordingly
				switch(modifyPhysicsObject->modifyWhatDataInPhysicsObjectData)
				{
				case XKILL_Enums::ModifyPhysicsObjectData::GRAVITY:
					{
						Float3* gravity = static_cast<Float3*>(modifyPhysicsObject->data);
						
						physicsObject->setGravity(btVector3(gravity->x, gravity->y, gravity->z));
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::VELOCITY:
					{
						Float3* velocity = static_cast<Float3*>(modifyPhysicsObject->data);
						
						physicsObject->setLinearVelocity(btVector3(velocity->x, velocity->y, velocity->z));
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::VELOCITYPERCENTAGE:
					{
						Float3* velocityPercentage = static_cast<Float3*>(modifyPhysicsObject->data);
						
						btVector3 currentLinearVelocity = physicsObject->getLinearVelocity();
						physicsObject->setLinearVelocity(btVector3(currentLinearVelocity.x()*velocityPercentage->x, currentLinearVelocity.y()*velocityPercentage->y, currentLinearVelocity.z()*velocityPercentage->z));
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::FLAG_STATIC:
					{
						bool* staticPhysicsObject = static_cast<bool*>(modifyPhysicsObject->data);
						
						if(*staticPhysicsObject == true)
						{
							physicsObject->setCollisionFlags(physicsObject->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
						}
						else if(*staticPhysicsObject == false)
						{
							physicsObject->setCollisionFlags(physicsObject->getCollisionFlags() & ~ btCollisionObject::CF_STATIC_OBJECT);
						}
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::COLLISIONFILTERMASK:
					{
						/*In order to modify "collisionFilterMask", a physics objects needs to be removed from the Bullet Physics dynamics world and then readded using "addRigidBody", where "collisionFilterMask" is passed as argument.
						Write physics object data to physics attribute, modify "collisionFilterMask", and set the "reloadDataIntoBulletPhysics" flag, and this class will handle the removal and addition of the physics object.*/
						
						short* collisionFilterMaskFromEvent = static_cast<short*>(modifyPhysicsObject->data);

						AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.at(physicsAttributeIndex);
						physicsObject->writeNonSynchronizedPhysicsObjectDataToPhysicsAttribute();
						ptr_physics->collisionFilterMask = *collisionFilterMaskFromEvent;
						ptr_physics->reloadDataIntoBulletPhysics = true;
					}
					break;
				case XKILL_Enums::ModifyPhysicsObjectData::GIVE_IMPULSE:
					{
						Float3* impulseVector = static_cast<Float3*>(modifyPhysicsObject->data);

						btVector3 impulse = convert(*impulseVector);
						physicsObject->applyCentralImpulse(impulse);
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::IF_TRUE_RECALCULATE_LOCAL_INERTIA_ELSE_SET_TO_ZERO:
					{
						bool* recalculateLocalInertia = static_cast<bool*>(modifyPhysicsObject->data);

						btVector3 localInertia = btVector3(0.0f, 0.0f, 0.0f);
						btScalar mass = itrPhysics.at(physicsAttributeIndex)->mass;
						if(*recalculateLocalInertia == true)
						{
							btCollisionShape* collisionShape = physicsObject->getCollisionShape();
							collisionShape->calculateLocalInertia(mass, localInertia);

							physicsObject->setMassProps(mass, localInertia);
							physicsObject->updateInertiaTensor();
						}
						else
						{
							physicsObject->setMassProps(mass, localInertia);
						}

						break;
					}
				}
			}
			else
			{
				ERROR_MESSAGEBOX("Invalid physics attribute id when handling event of type EVENT_MODIFY_PHYSICS_OBJECT, error 1");
			}
		}
		else
		{
			ERROR_MESSAGEBOX("Invalid physics attribute id when handling event of type EVENT_MODIFY_PHYSICS_OBJECT, error 2");
		}
		break;
	}
	case EVENT_CLOSEST_HIT_RAY_CAST:
		{
			Event_ClosestHitRayCast* event_ClosestRayCast = static_cast<Event_ClosestHitRayCast*>(e);
			handleEvent_ClosestRayCast(event_ClosestRayCast);
		break;
		}
	case EVENT_ALL_HITS_RAY_CAST:
		{
			Event_AllHitsRayCast* event_AllHitsRayCast = static_cast<Event_AllHitsRayCast*>(e);
			handleEvent_AllHitsRayCast(event_AllHitsRayCast);
		break;
		}
	case EVENT_LOAD_LEVEL_BULLET:
		CollisionShapes::Instance()->loadCollisionShapes();
		break;
	case EVENT_UNLOAD_LEVEL:
		CollisionShapes::Instance()->unloadCollisionShapes();
		break;
	case EVENT_NULL_PROCESS_STOPPED_EXECUTING:
		{
			//Reset apart-fallen world
			while(itrPhysics.hasNext())
			{
				AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.getNext();
				if(ptr_physics->collisionFilterGroup == XKILL_Enums::PhysicsAttributeType::PROP)
				{
					if(physicsObjects_->at(ptr_physics.index()) != nullptr)
					{
						PropPhysicsObject* propPhysicsObject = static_cast<PropPhysicsObject*>(physicsObjects_->at(ptr_physics.index()));
						
						ptr_physics->collisionFilterGroup = XKILL_Enums::PhysicsAttributeType::WORLD;
						ptr_physics->collisionFilterMask = XKILL_Enums::PhysicsAttributeType::PLAYER | XKILL_Enums::PhysicsAttributeType::PROJECTILE |
							XKILL_Enums::PhysicsAttributeType::FRUSTUM | XKILL_Enums::PhysicsAttributeType::PICKUPABLE |
							XKILL_Enums::PhysicsAttributeType::RAY | XKILL_Enums::PhysicsAttributeType::PROP;

						ptr_physics->ptr_spatial->ptr_position->position = Float3(propPhysicsObject->worldOrigin_.x(),propPhysicsObject->worldOrigin_.y(),propPhysicsObject->worldOrigin_.z());
					
						propPhysicsObject->setCollisionFlags(propPhysicsObject->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);//check, might not be needed

						ptr_physics->gravity = Float3(0.0f, 0.0f, 0.0f);
						ptr_physics->linearVelocity = Float3(0.0f, 0.0f, 0.0f);
						ptr_physics->mass = 0;
						ptr_physics->collisionResponse = true;

						SEND_EVENT(&Event_ReloadPhysicsAttributeDataIntoBulletPhysics(ptr_physics.index()));
					}
				}
			}
		break;
		}
	case EVENT_RELOAD_PHYSICS_ATTRIBUTE_DATA_INTO_BULLET_PHYSICS:
		{
			Event_ReloadPhysicsAttributeDataIntoBulletPhysics* event_ReloadPhysicsAttributeDataIntoBulletPhysics = static_cast<Event_ReloadPhysicsAttributeDataIntoBulletPhysics*>(e);
			int physicsAttributeId = event_ReloadPhysicsAttributeDataIntoBulletPhysics->physicsAttributeId;
			AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.at(physicsAttributeId);

			ptr_physics->reloadDataIntoBulletPhysics = true;
			synchronizeWithAttributes(ptr_physics, physicsAttributeId);

			break;
		}
	}
}
Пример #13
0
void CLogAnalyzerView::OnGeneratereportExcel()
{
#ifdef EXCEL_REPORT
    try
    {
        if (m_logger->GetFileName().empty())
            return;

        CApplication app;
        CWorkbook exlBook;  
        CWorkbooks exlBooks;  
        CWorksheet exlSheet;  
        CWorksheets exlSheets;
        CChart chart;
        CRange range;
        CChartObjects chartobjects;
        LPDISPATCH lpDisp;

        COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

        // Start Excel and get the Application object.
        if(!app.CreateDispatch("Excel.Application"))
        {
            ERROR_MESSAGEBOX("Couldn't start Excel and get an application 0bject");
            return;
        }

        app.put_Visible(TRUE);

        // Get Workbooks collection.
        lpDisp = app.get_Workbooks();
        ASSERT(lpDisp);
        // Attach the IDispatch pointer
        exlBooks.AttachDispatch(lpDisp);
        exlBook = exlBooks.Add(covOptional);

        // Get sheets.
        lpDisp = exlBook.get_Sheets();
        ASSERT(lpDisp);
        exlSheets.AttachDispatch(lpDisp);

        lpDisp = exlSheets.get_Item( COleVariant((short)(1)) );
        ASSERT(lpDisp);
        // Attach the lpDisp pointer to a Worksheet object.
        exlSheet.AttachDispatch(lpDisp);

        const std::map<tstring, Poco::SharedPtr<CComponent>>& componentMap = m_logger->GetComponents();
        char charPos[32];
        int nSize = 0;
        if (componentMap.size() > 0)
        {   
            std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = componentMap.begin();
            int nIndex = 3;

            while (ite != componentMap.end())
            {
                if (ite->second->GetTraceLogs().size() > 0)
                {
                    sprintf(charPos, "A%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    ASSERT(lpDisp);
                    range.AttachDispatch(lpDisp);  // Attach the IDispatch pointer
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(ite->second->GetComponentName().c_str()));
                    range.put_Value2(COleVariant(ite->second->GetComponentName().c_str()));

                    int nTrace = 0, nNotification = 0, nError = 0, nInformation = 0, nDebug = 0, nCritical = 0, nWarning = 0, nFatal = 0;
                    if (nSize == 0)
                    {
                        nTrace = 10;
                        nNotification = 10;
                        nError = 5, nInformation = 50, nDebug = 2, nCritical = 2, nWarning = 9, nFatal = 1;
                    }
                    else if (nSize == 1)
                    {
                        nTrace = 10;
                        nNotification = 25;
                        nError = 4, nInformation = 36, nDebug = 5, nCritical = 0, nWarning = 20, nFatal = 1;
                    }
                    else if (nSize == 2)
                    {
                        nTrace = 0;
                        nNotification = 5;
                        nError = 4, nInformation = 100, nDebug = 5, nCritical = 5, nWarning = 15, nFatal = 0;
                    }
                    else if (nSize == 3)
                    {
                        nTrace = 0;
                        nNotification = 5;
                        nError = 4, nInformation = 82, nDebug = 36, nCritical = 1, nWarning = 50, nFatal = 0;
                    }
                    //ite->second->getLogTypeCount(nTrace, nNotification, nError, nInformation, nDebug, nCritical, nWarning, nFatal);
                    //Trace
                    sprintf(charPos, "B%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nTrace);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Debug
                    sprintf(charPos, "C%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nDebug);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Information
                    sprintf(charPos, "D%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nInformation);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Warning
                    sprintf(charPos, "E%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nWarning);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Error
                    sprintf(charPos, "F%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nError);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Critical
                    sprintf(charPos, "G%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nCritical);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Notification
                    sprintf(charPos, "H%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nNotification);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    //Fatal
                    sprintf(charPos, "I%d", nIndex);
                    lpDisp = exlSheet.get_Range(COleVariant(charPos), COleVariant(charPos));
                    range.AttachDispatch(lpDisp);
                    sprintf(charPos, "%d", nFatal);
                    range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant(charPos));
                    range.put_Value2(COleVariant(charPos));
                    ++nIndex;
                    ++nSize;
                }
                ++ite;
            }
        }

        lpDisp = exlSheet.get_Range(COleVariant("B2"), COleVariant("B2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("TRACE"));
        range.put_Value2(COleVariant("TRACE"));

        lpDisp = exlSheet.get_Range(COleVariant("C2"), COleVariant("C2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("DEBUG"));
        range.put_Value2(COleVariant("DEBUG"));

        lpDisp = exlSheet.get_Range(COleVariant("D2"), COleVariant("D2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("INFORMATION"));
        range.put_Value2(COleVariant("INFORMATION"));

        lpDisp = exlSheet.get_Range(COleVariant("E2"), COleVariant("E2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("WARNING"));
        range.put_Value2(COleVariant("WARNING"));

        lpDisp = exlSheet.get_Range(COleVariant("F2"), COleVariant("F2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("ERROR"));
        range.put_Value2(COleVariant("ERROR"));

        lpDisp = exlSheet.get_Range(COleVariant("G2"), COleVariant("G2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("CRITICAL"));
        range.put_Value2(COleVariant("CRITICAL"));

        lpDisp = exlSheet.get_Range(COleVariant("H2"), COleVariant("H2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("NOTIFICATION"));
        range.put_Value2(COleVariant("NOTIFICATION"));

        lpDisp = exlSheet.get_Range(COleVariant("I2"), COleVariant("I2"));
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);
        range.put_Value(COleVariant((long)DISP_E_PARAMNOTFOUND, VT_ERROR), COleVariant("FATAL"));
        range.put_Value2(COleVariant("FATAL"));

        // The cells are populated. To start the chart,
        // declare some long variables and site the chart.
        long left, top, width, height;
        left = 200;
        top = 200;
        width = 450;
        height = 350;

        lpDisp = exlSheet.ChartObjects(covOptional);

        ASSERT(lpDisp);
        chartobjects.AttachDispatch(lpDisp); // Attach the lpDisp pointer
        // for ChartObjects to the chartobjects
        // object.
        CChartObject chartobject = chartobjects.Add(left, top, width, height); 
        //defines the rectangle, 
        // adds a new chart at that rectangle and 
        // assigns its object reference to a 
        // ChartObject variable named chartobject
        chart.AttachDispatch(chartobject.get_Chart());

        sprintf(charPos, "I%d", nSize + 2);
        lpDisp = exlSheet.get_Range(COleVariant("A2"), COleVariant(charPos));
        // The range containing the data to be charted.
        ASSERT(lpDisp);
        range.AttachDispatch(lpDisp);

        VARIANT var; // ChartWizard needs a Variant for the Source range.
        var.vt = VT_DISPATCH; // .vt is the usable member of the tagVARIANT
        var.pdispVal = lpDisp; // Assign IDispatch pointer

        chart.ChartWizard(var,                    // Source.
            COleVariant((short)52),  // Gallery: stacked column.
            covOptional,             // Format, use default.
            COleVariant((short)1),   // PlotBy: xlRows.
            COleVariant((short)1),   // CategoryLabels.
            COleVariant((short)1),   // SeriesLabels.
            COleVariant((short)TRUE),  // HasLegend.
            COleVariant("Trace Report"),  // Title.
            COleVariant("Components"),    // CategoryTitle.
            COleVariant("Trace Count"),  // ValueTitles.
            covOptional              // ExtraTitle.
            );

        range.ReleaseDispatch();   
        exlSheet.ReleaseDispatch();   
        exlSheets.ReleaseDispatch();   
        exlBook.ReleaseDispatch();   
        exlBooks.ReleaseDispatch();
        chart.ReleaseDispatch();
        chartobject.ReleaseDispatch();
        app.ReleaseDispatch();
    }
    catch(COleException *e)
    {
        char buf[1024];
        sprintf(buf, "COleException. SCODE: %08lx.", (long)e->m_sc);
        ::MessageBox(NULL, buf, "COleException", MB_SETFOREGROUND | MB_OK);
    }

    catch(COleDispatchException *e)
    {
        char buf[1024];
        sprintf(buf,
            "COleDispatchException. SCODE: %08lx, Description: \"%s\".", (long)e->m_wCode,
            (LPSTR)e->m_strDescription.GetBuffer(1024));
        ::MessageBox(NULL, buf, "COleDispatchException", MB_SETFOREGROUND | MB_OK);
    }

    catch(...)
    {
        ::MessageBox(NULL, "General Exception caught.", "Catch-All", MB_SETFOREGROUND | MB_OK);
    }
#endif
}
Пример #14
0
void CLogAnalyzerView::OnEditOpensourcefile()
{
    if (m_logger->GetActiveUISetting().isNull())
    {
        ERROR_MESSAGEBOX("UI Setting has incorrect info.");
        return;
    }

    BOOL bPython = m_logger->GetActiveUISetting()->GetPythonModuleFlag();
    int nIdentifier = m_logger->GetActiveUISetting()->GetColumnIdentifier();
    if (nIdentifier == -1 && !bPython)
    {
        ERROR_MESSAGEBOX("Cannot open related source file since this UI Setting doesn't have column identifier or define python function.");
        return;
    }

    //Get the selected component name
    tstring strText(m_strSelComponent.GetBuffer(m_strSelComponent.GetLength())); 
    //Get the selected trace log

    const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents();
    std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strText);

    HCURSOR holdcursor, hwaitcursor;
    hwaitcursor = LoadCursor(NULL,IDC_WAIT);
    holdcursor = ::SetCursor(hwaitcursor);

    try
    {
        if (ite != components.end())
        {
            //Search trace log
            const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs();
            for (int i = 0; i < traceLogs.size(); ++i)
            {
                TCHAR itemText[512] = {0};
                POSITION pt = m_traceList.GetFirstSelectedItemPosition();
                int nSelIndex = m_traceList.GetNextSelectedItem(pt);
                CString strLine = m_traceList.GetItemText(nSelIndex, 0);
                int nLine = Poco::NumberParser::parse(strLine.GetBuffer(strLine.GetLength()));
                if (nLine == traceLogs.at(i)->m_nLine)
                {
                    m_logger->GetAssocatedSourceFiles(traceLogs.at(i));
                    if (!traceLogs.at(i)->m_strSourceCodeFile.empty())
                    {
                        //Open file and go to the specify line
                        std::vector<tstring> args;
                        itoa(traceLogs.at(i)->m_nLineInSourceFile, itemText, 10);
                        tstring strCommandLine = m_logger->GetActiveUISetting()->GetNodepadPath();
                        strCommandLine += " -n";
                        strCommandLine += itemText;
                        strCommandLine += " \"";
                        strCommandLine += traceLogs.at(i)->m_strSourceCodeFile;
                        strCommandLine += "\"";
                        Poco::Process::launch(strCommandLine, args);
                        break;
                    }
                    else
                        ERROR_MESSAGEBOX("Cannot find the trace Id, Please modify the path for the related component.");
                    break;
                }
            }
        }
    }
    catch (std::exception& e)
    {
        CString strMessage = "Exception :";
        strMessage += e.what();
        ERROR_MESSAGEBOX(strMessage);
    }
    catch (...)
    {
        ERROR_MESSAGEBOX("Unknown exception");
    }
    ::SetCursor(holdcursor);
}
Пример #15
0
bool LoaderFbx::loadScene(std::string filename)
{
	bool success = true;

	int fileMajor, fileMinor, fileRevision;
	int sdkMajor, sdkMinor, sdkRevision;
	std::stringstream message;

	FbxManager::GetFileFormatVersion(sdkMajor, sdkMinor, sdkRevision);

	FbxImporter* fbxImporter = FbxImporter::Create(fbxManager_, "");
	success = fbxImporter->Initialize(filename.c_str(), -1, fbxManager_->GetIOSettings());
	fbxImporter->GetFileVersion(fileMajor, fileMinor, fileRevision);

	if(!success)
	{
		message.str("");
		message << "LoaderFbx::loadScene | Call to FbxImporter::Initialize() failed! \n Error returned: " 
				<< fbxImporter->GetStatus().GetErrorString();
		ERROR_MESSAGEBOX(message.str());

		if(fbxImporter->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion)
		{
			std::stringstream message;
			message.str("");
			message << "FBX file format version for this FBX SDK is " << sdkMajor << "." << sdkMinor << "." << sdkRevision << "\n"
					<< "FBX file format version for file " << filename << " is " << fileMajor << "." << fileMinor << "." << fileRevision;
			ERROR_MESSAGEBOX(message.str());
		}
	}
	if(fbxImporter->IsFBX())
	{
		FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", filename, fileMajor, fileMinor, fileRevision);

        // From this point, it is possible to access animation stack information without
        // the expense of loading the entire file.

        FBXSDK_printf("Animation Stack Information\n");

        int animStackCount = fbxImporter->GetAnimStackCount();

        FBXSDK_printf("    Number of Animation Stacks: %d\n", animStackCount);
        FBXSDK_printf("    Current Animation Stack: \"%s\"\n", fbxImporter->GetActiveAnimStackName().Buffer());
        FBXSDK_printf("\n");

        for(int i = 0; i < animStackCount; i++)
        {
            FbxTakeInfo* takeInfo = fbxImporter->GetTakeInfo(i);

            FBXSDK_printf("    Animation Stack %d\n", i);
            FBXSDK_printf("         Name: \"%s\"\n", takeInfo->mName.Buffer());
			const char* debug = takeInfo->mDescription.Buffer();
	//		FBXSDK_printf("         Description: \"%s\"\n", takeInfo->mDescription.Buffer());
            
			// Change the value of the import name if the animation stack should be imported 
            // under a different name.
            FBXSDK_printf("         Import Name: \"%s\"\n", takeInfo->mImportName.Buffer());

            // Set the value of the import state to false if the animation stack should be not
            // be imported. 
            FBXSDK_printf("         Import State: %s\n", takeInfo->mSelect ? "true" : "false");
            FBXSDK_printf("\n");

			
        }

        // Set the import states. By default, the import states are always set to 
        // true. The code below shows how to change these states.
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_MATERIAL,        true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_TEXTURE,         true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_LINK,            true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_SHAPE,           true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_GOBO,            true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_ANIMATION,       true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
	}
	
	if(success)
	{
		success = fbxImporter->Import(fbxScene_);
	}

	if(!success)
	{
		message.str("");
		message << "LoaderFbx::loadScene | Call to FbxImporter::Import() failed! \n Error returned: "
				<< fbxImporter->GetStatus().GetErrorString();
		ERROR_MESSAGEBOX(message.str());
	}

	return success;
}