//////////////////////////////////////////////////////////////////////////
// initialise
//virtual
void ScnParticleSystemComponent::initialise( const Json::Value& Object )
{
	Super::initialise( Object );

	// Grab number of particles.
	NoofParticles_ = Object["noofparticles"].asUInt();
	ScnMaterialRef Material = getPackage()->getPackageCrossRef( Object["material"].asUInt() );
	if( !CsCore::pImpl()->createResource( BcName::INVALID, getPackage(), MaterialComponent_, Material, scnSPF_PARTICLE_3D ) )
	{
		BcAssertMsg( BcFalse, "Material invalid blah." );
	}

	IsLocalSpace_ = Object["localspace"].asBool();

	// Cache texture bounds.
	ScnTextureRef Texture = Material->getTexture( "aDiffuseTex" );
	for( BcU32 Idx = 0; Idx < Texture->noofRects(); ++Idx )
	{
		ScnRect Rect = Texture->getRect( Idx );
		UVBounds_.push_back( MaVec4d( Rect.X_, Rect.Y_, Rect.X_ + Rect.W_, Rect.Y_ + Rect.H_ ) );
	}

	WorldTransformParam_ = MaterialComponent_->findParameter( "uWorldTransform" );

	BcMemZero( &VertexBuffers_, sizeof( VertexBuffers_ ) );
	pParticleBuffer_ = NULL;
	CurrentVertexBuffer_ = 0;

	PotentialFreeParticle_ = 0;
}
Exemplo n.º 2
0
//////////////////////////////////////////////////////////////////////////
// create
//virtual
void ScnDebugRenderComponent::initialise( const Json::Value& Object )
{
	ScnDebugRenderComponent::initialise( Object[ "noofvertices" ].asUInt() );

	ScnMaterialRef Material = getPackage()->getPackageCrossRef( Object[ "material" ].asUInt() );

	CsCore::pImpl()->createResource( BcName::INVALID, getPackage(), MaterialComponent_, Material, scnSPF_STATIC_3D | scnSPF_UNLIT );
}
Exemplo n.º 3
0
//////////////////////////////////////////////////////////////////////////
// fileChunkReady
void ScnComponent::fileChunkReady( BcU32 ChunkIdx, BcU32 ChunkID, void* pData )
{
	if( ChunkID == BcHash( "object" ) )
	{
		pJsonObject_ = reinterpret_cast< const BcChar* >( pData );

		// Initialise json object.
	    Json::Value Root;
	    Json::Reader Reader;
	    if( Reader.parse( pJsonObject_, Root ) )
		{
			// New way.
			CsSerialiserPackageObjectCodec ObjectCodec( getPackage(), bcRFF_IMPORTER, bcRFF_NONE, bcRFF_IMPORTER );
			SeJsonReader Reader( &ObjectCodec );

			Reader.serialiseClassMembers( this, this->getClass(), Root, 0 );

			// Now reinitialise.
			initialise();
		}
		else
		{
			BcBreakpoint;
		}

		CsResource::markCreate();
		CsResource::markReady();
	}
}
Exemplo n.º 4
0
void Simple::build(bool modeling)
{
    Gtk::VBox* vbox;

    vle::utils::Package pack(getPackage());

    std::string glade = pack.getPluginGvleModelingFile(
                "DifferenceEquation.glade", vle::utils::PKG_BINARY);

    mXml = Gtk::Builder::create();
    mXml->add_from_file(glade.c_str());

    mXml->get_widget("DialogPluginSimpleBox", m_dialog);
    m_dialog->set_title("DifferenceEquation - Simple");
    mXml->get_widget("SimplePluginVBox", vbox);

    vbox->pack_start(mNameValue.build(mXml));
    vbox->pack_start(mTimeStep.build(mXml));
    if (modeling) {
        vbox->pack_start(mParameters.build(mXml));

        {
            m_buttonSource = Gtk::manage(
                new Gtk::Button("Compute / InitValue / User section"));
            m_buttonSource->show();
            vbox->pack_start(*m_buttonSource);
            mList.push_back(m_buttonSource->signal_clicked().connect(
                                sigc::mem_fun(*this, &Plugin::onSource)));
        }
    }
    vbox->pack_start(mMapping.build(mXml));
}
Exemplo n.º 5
0
bool Map::undoPackage (int col, int row, int targetCol, int targetRow)
{
	MapTile* package = getPackage(col, row);
	if (package != nullptr) {
		info(LOG_SERVER, "move package back");
		rebuildField();
		const int origCol = package->getCol();
		const int origRow = package->getRow();
		if (!package->setPos(targetCol, targetRow))
			return false;
		rebuildField();
		const int index = INDEX(targetCol, targetRow);
		StateMapConstIter i = _state.find(index);
		if (i == _state.end()) {
			package->setPos(origCol, origRow);
			return false;
		}

		const char c = i->second;
		if (c == Sokoban::PACKAGEONTARGET)
			package->setState(CavePackerEntityStates::DELIVERED);
		else
			package->setState(CavePackerEntityStates::NONE);

		--_pushes;
		return true;
	}
	info(LOG_SERVER, "don't move package back");
	return false;
}
Exemplo n.º 6
0
//////////////////////////////////////////////////////////////////////////
// initialise
//virtual
void ScnViewComponent::initialise( const Json::Value& Object )
{
	initialise();

	X_ = (BcF32)Object[ "x" ].asDouble();
	Y_ = (BcF32)Object[ "y" ].asDouble();
	Width_ = (BcF32)Object[ "width" ].asDouble();
	Height_ = (BcF32)Object[ "height" ].asDouble();
	Near_ = (BcF32)Object[ "near" ].asDouble();
	Far_ = (BcF32)Object[ "far" ].asDouble();
	HorizontalFOV_ = (BcF32)Object[ "hfov" ].asDouble();
	VerticalFOV_ = (BcF32)Object[ "vfov" ].asDouble();

	const Json::Value& RenderMaskValue = Object[ "rendermask" ];
	if( RenderMaskValue.type() != Json::nullValue )
	{
		setRenderMask( RenderMaskValue.asUInt() );
	}

	const Json::Value& RenderTargetValue = Object[ "rendertarget" ];
	if( RenderTargetValue.type() != Json::nullValue )
	{
		RenderTarget_ = getPackage()->getPackageCrossRef( RenderTargetValue.asUInt() );
	}
}
Exemplo n.º 7
0
//////////////////////////////////////////////////////////////////////////
// getChunk
void CsResource::requestChunk( BcU32 Chunk, void* pDataLocation )
{
	if( Index_ != BcErrorCode )
	{
		if( !getPackage()->requestChunk( Index_, Chunk, pDataLocation ) )
		{
	
		}
	}
}
Exemplo n.º 8
0
void serialEvent(){

    int len;
    uint16_t value;
    uint16_t i = 0;

   if( Serial.available() > 0 ) {
       received_command = Serial.read();
       len = getPackage();
       while(i<len){
         value = getPackage();
         data_table[i] = value * LASER_POINT_SCALER;
         i++;
       }
    } 
 
    len = 0;
    i = 0;
    data_received = true;

}
Exemplo n.º 9
0
//////////////////////////////////////////////////////////////////////////
// getNoofChunks
BcU32 CsResource::getNoofChunks() const
{
	if( Index_ != BcErrorCode )
	{
		return getPackage()->getNoofChunks( Index_ );
	}
	else
	{
		BcPrintf( "WARNING: Attempting to get number of chunks where we have an invalid index. Resource: %s\n", (*getName()).c_str() );
	}

	return 0;
}
Exemplo n.º 10
0
//////////////////////////////////////////////////////////////////////////
// getChunkSize
BcU32 CsResource::getChunkSize( BcU32 Chunk )
{
	if( Index_ != BcErrorCode )
	{
		return getPackage()->getChunkSize( Index_, Chunk );
	}
	else
	{
		BcPrintf( "WARNING: Attempting to get chunk size where we have an invalid index. Resource: %s\n", (*getName()).c_str() );
	}

	return 0;
}
Exemplo n.º 11
0
void TPKGS::loadPackages() {
	File f(_mainPackageDir);
	for(File::dir_iterator a = f.begin(); a != f.end(); ++a) {
		if(a.isHidden() || a.isLink() || !a.isDir()) {
			continue;
		}
		const PName name = a.getFile();
		try {
			getPackage(name);
		} catch(std::exception &err) {
			std::cerr << "Package " << name << ": Error: " << err.what() << std::endl;
		}
	}
	_arePackagesLoaded = true;
}
Exemplo n.º 12
0
    uint16_t ZMCamera::processAllPackagesToFile(Stream * output) {
      uint16_t t_total = 0;
      for (uint16_t t_packid=1; t_packid <= _snapshotpackagecount; t_packid++) {
        debugStream->print("get package ");
        debugStream->print(t_packid);
        uint16_t t_err = getPackage(t_packid);
        if (t_err == 0)
          return(0);
        debugStream->print(" ");
        debugStream->println(getPackageLength());
        output->write(getPackagePTR(), getPackageLength());
        output->flush();
        t_total += getPackageLength();
//        t_packid++;
      }
      return(t_total);
    };
/**
 * Overwritten by Ruby language implementation to get lowercase path.
 */
QString RubyClassifierCodeDocument::getPath()
{
    QString path = getPackage();

    // Replace all white spaces with blanks
    path = path.simplified();

    // Replace all blanks with underscore
    path.replace(QRegExp(QLatin1String(" ")), QLatin1String("_"));

    path.replace(QRegExp(QLatin1String("\\.")),QLatin1String("/"));
    path.replace(QRegExp(QLatin1String("::")), QLatin1String("/"));

    path = path.toLower();

    return path;
}
Exemplo n.º 14
0
bool Map::movePlayer (Player* player, char step)
{
	int x;
	int y;
	getXY(step, x, y);
	debug(LOG_SERVER, String::format("move player %i:%i (current: %i:%i)", x, y, player->getCol(), player->getRow()));
	// move player and move touching packages
	const int targetCol = player->getCol() + x;
	const int targetRow = player->getRow() + y;
	MapTile* package = getPackage(targetCol, targetRow);
	if (package != nullptr) {
		const int pCol = targetCol + x;
		const int pRow = targetRow + y;
		if (!isFree(pCol, pRow)) {
			debug(LOG_SERVER, "can't move here - can't move package. target field is blocked");
			return false;
		}
		if (!package->setPos(pCol, pRow)) {
			debug(LOG_SERVER, "failed to move the package - thus can't move the player");
			return false;
		}
		debug(LOG_SERVER, String::format("moved package %i", package->getID()));
		increasePushes();
		rebuildField();
		if (isTarget(pCol, pRow)) {
			package->setState(CavePackerEntityStates::DELIVERED);
			debug(LOG_SERVER, String::format("mark package as delivered %i", package->getID()));
		} else if (package->getState() == CavePackerEntityStates::DELIVERED) {
			debug(LOG_SERVER, String::format("reset package state %i", package->getID()));
			package->setState(CavePackerEntityStates::NONE);
		}
		// sokoban standard - if a package was moved, the move char is uppercase
		step = toupper(step);
	}
	if (!player->setPos(targetCol, targetRow)) {
		debug(LOG_SERVER, "failed to move the player");
		return false;
	}

	player->storeStep(step);
	increaseMoves();
	return true;
}
Exemplo n.º 15
0
int main() {

    connection conn;
    package p;


    if( openSocket( &conn ) != 1 )
        printf("Erro ao abrir socket!");

    do {
        getPackage( &conn, &p );

        if( !verifyIntegrity( &p ) )
            printf("Mensagem com erro!");

        executeCommand( &p );
    } while(1);
    

    return 1;
}
Exemplo n.º 16
0
Package &Popt::getPackage(Version &v1, Version &v2) {
	v1 = v2 = Version::EMPTY_VERSION;
	Package &p = getPackage(v1, NONE_NEEDED, false);
	if(!hasMoreArgs()) {
		// No more args, v1 may be set
		return p;
	}
	if(v1.isEmptyVersion()) { // v1 is empty and we have more arguments, extract v1 from them
		v1 = getVersion(p, NO_DEFAULT, false);
		assert(!v1.isEmptyVersion());
		if(!hasMoreArgs()) {
			// No more args, v1 is set, v2 not
			return p;
		}
	}
	assert(hasMoreArgs()); // We did check this after the above getPackage and getVersion calls.
	assert(v2.isEmptyVersion()); // Never written to it
	v2 = getVersion(p, NO_DEFAULT, false);
	assert(!v2.isEmptyVersion());
	return p;
}
Exemplo n.º 17
0
Package &Popt::getPackage2(Version &v) {
	if(_args.size() == 1) {
		// Only one argument, assume this to be the version
		std::string pname = popArg();
		if(extractPackageAndVersionFromString(pname, v)) {
			// pname had a package name _and_ a version, that's all we need, v is already written.
			return _tp.getPackage(pname);
		}
		// Now we have either a package name and no version string
		// or only a version string and no package name.
		// See if we have a default package name.
		const std::string defaultPName = getDefaultPackageName();
		if(!defaultPName.empty()) {
			// OK, we have a default package name, assume the argument to be the version
			v = pname;
			return _tp.getPackage(defaultPName);
		}
		// Initialy there was only one argument, it had been removed at the call to popArg
		// above, now the getPackage will fail with a more or less meaningfull message.
		assert(_args.empty());
	}
	// At least two arguments, use the normal algorithm
	return getPackage(v, NO_DEFAULT, false);
}
Exemplo n.º 18
0
void Map::startMap ()
{
	rebuildField();
	for (PlayerListIter i = _playersWaitingForSpawn.begin(); i != _playersWaitingForSpawn.end(); ++i) {
		spawnPlayer(*i);
	}
	_playersWaitingForSpawn.clear();

	INetwork& network = _serviceProvider->getNetwork();
	network.sendToAllClients(StartMapMessage());

	for (int row = 0; row < _height; ++row) {
		for (int col = 0; col < _width; ++col) {
			StateMapConstIter i = _state.find(INDEX(col, row));
			if (i == _state.end())
				continue;
			const char c = i->second;
			if (c != Sokoban::PACKAGEONTARGET)
				continue;

			getPackage(col, row)->setState(CavePackerEntityStates::DELIVERED);
		}
	}
}
Exemplo n.º 19
0
//////////////////////////////////////////////////////////////////////////
// getName
const BcName& CsResource::getPackageName() const
{
	return getPackage() != nullptr ? getPackage()->getName() : BcName::INVALID;
}
Exemplo n.º 20
0
Package &Popt::getPackage() {
	Version dummy;
	return getPackage(dummy, NONE_NEEDED, false);
}
Exemplo n.º 21
0
const std::shared_ptr<BasicItem> ResourceManager::getItem(const std::string& package,
                                                     const std::string& name) {
    auto pkg = getPackage(package);
    return pkg->getItem(name);
}
Exemplo n.º 22
0
//////////////////////////////////////////////////////////////////////////
// create
//virtual
void ScnModel::create()
{
	// NOTE: This should try and compact index and vertex buffers so we create less
	//       GPU resources. This could be done import time, but it could vary
	//       platform to platform.
	//       Also, if we compact, we will need to split it all up by vertex format,
	//       possibly even sort it by vertex format.
	
	// Setup primitive runtime.
	MeshRuntimes_.reserve( pHeader_->NoofPrimitives_ );
	
	BcU8* pVertexBufferData = pVertexBufferData_;
	BcU8* pIndexBufferData = pIndexBufferData_;
	
	for( BcU32 PrimitiveIdx = 0; PrimitiveIdx < pHeader_->NoofPrimitives_; ++PrimitiveIdx )
	{
		ScnModelMeshData* pMeshData = &pMeshData_[ PrimitiveIdx ];
		
		//ScnModelNodeTransformData* pNodeTransformData = &pNodeTransformData_[ pMeshData->NodeIndex_ ];
		
		// Create GPU resources.
		RsVertexDeclarationDesc VertexDeclarationDesc( pMeshData_->NoofVertexElements_ );
		for( BcU32 Idx = 0; Idx < pMeshData->NoofVertexElements_; ++Idx )
		{
			VertexDeclarationDesc.addElement( pMeshData_->VertexElements_[ Idx ] );
		}
		
		RsVertexDeclaration* pVertexDeclaration = RsCore::pImpl()->createVertexDeclaration( VertexDeclarationDesc );
		BcU32 VertexBufferSize = pMeshData->NoofVertices_ * pMeshData->VertexStride_;
		RsBuffer* pVertexBuffer = RsCore::pImpl()->createBuffer( 
			RsBufferDesc( 
				RsBufferType::VERTEX, 
				RsResourceCreationFlags::STATIC,
				VertexBufferSize ) );

		RsCore::pImpl()->updateBuffer( 
			pVertexBuffer, 0, pMeshData->NoofVertices_ * pMeshData->VertexStride_, 
			RsResourceUpdateFlags::ASYNC,
			[ pVertexBufferData, VertexBufferSize ]
			( RsBuffer* Buffer, const RsBufferLock& BufferLock )
			{
				BcAssert( Buffer->getDesc().SizeBytes_ == VertexBufferSize );
				BcMemCopy( BufferLock.Buffer_, pVertexBufferData, 
					VertexBufferSize );
			} );
	
		BcU32 IndexBufferSize = pMeshData->NoofIndices_ * sizeof( BcU16 );
		RsBuffer* pIndexBuffer = 
			RsCore::pImpl()->createBuffer( 
				RsBufferDesc( 
					RsBufferType::INDEX, 
					RsResourceCreationFlags::STATIC, 
					IndexBufferSize ) );

		RsCore::pImpl()->updateBuffer( 
			pIndexBuffer, 0, pMeshData->NoofIndices_ * sizeof( BcU16 ), 
			RsResourceUpdateFlags::ASYNC,
			[ pIndexBufferData, IndexBufferSize ]
			( RsBuffer* Buffer, const RsBufferLock& BufferLock )
			{
				BcAssert( Buffer->getDesc().SizeBytes_ == IndexBufferSize );
				BcMemCopy( BufferLock.Buffer_, pIndexBufferData, 
					IndexBufferSize );
			} );
		
		// Setup runtime structure.
		ScnModelMeshRuntime MeshRuntime = 
		{
			PrimitiveIdx,
			pVertexDeclaration,
			pVertexBuffer,
			pIndexBuffer,
			nullptr
		};
		
		// Get resource.
		auto Resource = getPackage()->getCrossRefResource( pMeshData->MaterialRef_ );
		MeshRuntime.MaterialRef_ = Resource;
		BcAssertMsg( MeshRuntime.MaterialRef_.isValid(), "ScnModel: Material reference is invalid. Packing error." );

		// Push into array.
		MeshRuntimes_.push_back( MeshRuntime );
		
		// Advance vertex and index buffers.
		pVertexBufferData += pMeshData->NoofVertices_ * pMeshData->VertexStride_;
		pIndexBufferData += pMeshData->NoofIndices_ * sizeof( BcU16 );
	}

	// Mark as ready.
	markReady();
}
Exemplo n.º 23
0
void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest )
{
    QFile f( packageFile );
    if ( !f.open( IO_ReadOnly ) )
        return;
    QTextStream t( &f );

    QString line;
    QString key;
    QString value;
    int pos;

    if ( clearAll )
        cleanUp();
    Package *currPackage = 0;

    bool newPackage = true;
    while ( !t.eof() )
    {
        line = t.readLine();

        pos = line.find( ':', 0 );
        if ( pos > -1 )
            key = line.mid( 0, pos ).stripWhiteSpace();
        else
            key = QString::null;
        value = line.mid( pos+1, line.length()-pos ).stripWhiteSpace();

        if ( key == "Package" && newPackage )
        {
            newPackage = false;

            currPackage = getPackage( value );
            if ( !currPackage )
            {
                Package *package = new Package( value );
                packageList.append( package );
                currPackage = package;
                currPackage->setInstalledTo( dest );
                if ( installingToRoot )
                    currPackage->setInstalledToRoot( true );
            }
            else
            {
                if ( currPackage->isInstalled() )
                    currPackage->setInstalledTo( dest );
            }
        }
        else if ( key == "Version" )
        {
            if ( currPackage )
                currPackage->setVersion( value );
        }
        else if ( key == "Status" )
        {
            if ( currPackage )
                currPackage->setStatus( value );
        }
        else if ( key == "Description" )
        {
            if ( currPackage )
                currPackage->setDescription( value );
        }
        else if ( key == "Filename" )
        {
            if ( currPackage )
                currPackage->setFilename( value );
        }
        else if ( key == "Size" )
        {
            if ( currPackage )
                currPackage->setPackageSize( value );
        }
        else if ( key == "Section" )
        {
            if ( currPackage )
                currPackage->setSection( value );

            DataManager::setAvailableCategories( value );
        }
        else if ( key == QString::null )
        {
            newPackage = true;
        }
    }

    f.close();

    // build local packages
    buildLocalPackages( local );
}
Exemplo n.º 24
0
Package *Server :: getPackage( QString &name )
{
    return getPackage( (const char *)name );
}
Exemplo n.º 25
0
//////////////////////////////////////////////////////////////////////////
// getString
const BcChar* CsResource::getString( BcU32 Offset ) const
{
	return getPackage()->getString( Offset );
}
Exemplo n.º 26
0
//////////////////////////////////////////////////////////////////////////
// markupName
void CsResource::markupName( BcName& Name ) const
{
	getPackage()->markupName( Name );
}
Exemplo n.º 27
0
// This method will cause the class to rebuild its text representation.
// based on the parent classifier object.
// For any situation in which this is called, we are either building the code
// document up, or replacing/regenerating the existing auto-generated parts. As
// such, we will want to insert everything we resonablely will want
// during creation. We can set various parts of the document (esp. the
// comments) to appear or not, as needed.
void DClassifierCodeDocument::updateContent()
{
    // Gather info on the various fields and parent objects of this class...
    UMLClassifier * c = getParentClassifier();
    Q_ASSERT(c != 0);
    CodeGenerationPolicy * commonPolicy = UMLApp::app()->commonPolicy();
    CodeGenPolicyExt * pe = UMLApp::app()->policyExt();
    DCodeGenerationPolicy * policy = dynamic_cast<DCodeGenerationPolicy*>(pe);

    // first, set the global flag on whether or not to show classfield info
    // This depends on whether or not we have attribute/association classes
    const CodeClassFieldList * cfList = getCodeClassFieldList();
    CodeClassFieldList::const_iterator it = cfList->begin();
    CodeClassFieldList::const_iterator end = cfList->end();
    for (; it != end; ++it) {
        CodeClassField * field = *it;
        if (field->parentIsAttribute())
            field->setWriteOutMethods(policy->getAutoGenerateAttribAccessors());
        else
            field->setWriteOutMethods(policy->getAutoGenerateAssocAccessors());
    }

    // attribute-based ClassFields
    // we do it this way to have the static fields sorted out from regular ones
    CodeClassFieldList staticAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, true);
    CodeClassFieldList attribClassFields = getSpecificClassFields (CodeClassField::Attribute, false);
    // association-based ClassFields
    // don't care if they are static or not..all are lumped together
    CodeClassFieldList plainAssocClassFields = getSpecificClassFields (CodeClassField::PlainAssociation);
    CodeClassFieldList aggregationClassFields = getSpecificClassFields (CodeClassField::Aggregation);
    CodeClassFieldList compositionClassFields = getSpecificClassFields (CodeClassField::Composition);

    bool isInterface = parentIsInterface();
    bool hasOperationMethods = false;

    UMLOperationList list = c->getOpList();
    hasOperationMethods = ! list.isEmpty();

    QString endLine = commonPolicy->getNewLineEndingChars(); // a shortcut..so we don't have to call this all the time

    //
    // START GENERATING CODE/TEXT BLOCKS and COMMENTS FOR THE DOCUMENT
    //

    //
    // PACKAGE CODE BLOCK
    //
    QString pkgs = getPackage();
    pkgs.replace(QRegExp(QLatin1String("::")), QLatin1String("."));
    QString packageText = getPackage().isEmpty() ? QString() : QString(QLatin1String("package ")+pkgs+QLatin1Char(';')+endLine);
    CodeBlockWithComments * pblock = addOrUpdateTaggedCodeBlockWithComments(QLatin1String("packages"), packageText, QString(), 0, false);
    if (packageText.isEmpty() && pblock->contentType() == CodeBlock::AutoGenerated)
        pblock->setWriteOutText(false);
    else
        pblock->setWriteOutText(true);

    // IMPORT CODEBLOCK
    //
    // Q: Why all utils? Aren't just List and Vector the only classes we are using?
    // A: doesn't matter at all; it is more readable to just include '*' and d compilers
    //    don't slow down or anything. (TZ)
    QString importStatement;
    if (hasObjectVectorClassFields())
        importStatement.append(QLatin1String("import d.util.*;"));

    //only import classes in a different package from this class
    UMLPackageList imports;
    QMap<UMLPackage*, QString> packageMap; // so we don't repeat packages

    CodeGenerator::findObjectsRelated(c, imports);
    for (UMLPackageListIt importsIt(imports); importsIt.hasNext();) {
        UMLPackage *con = importsIt.next();
        // NO (default) datatypes in the import statement.. use defined
        // ones whould be possible, but no idea how to do that...at least for now.
        // Dynamic casting is slow..not an optimal way to do this.
        if (!packageMap.contains(con) && !con->isUMLDatatype())
        {
            packageMap.insert(con, con->package());

            // now, we DON'T need to import classes that are already in our own package
            // (that is, IF a package is specified). Otherwise, we should have a declaration.
            if (con->package() != c->package() ||
                    (c->package().isEmpty() && con->package().isEmpty()))
            {
                importStatement.append(endLine+QLatin1String("import "));
                if (!con->package().isEmpty())
                    importStatement.append(con->package()+QLatin1Char('.'));
                importStatement.append(CodeGenerator::cleanName(con->name())+QLatin1Char(';'));
            }
        }
    }
    // now, add/update the imports codeblock
    CodeBlockWithComments * iblock = addOrUpdateTaggedCodeBlockWithComments(QLatin1String("imports"), importStatement, QString(), 0, false);
    if (importStatement.isEmpty() && iblock->contentType() == CodeBlock::AutoGenerated)
        iblock->setWriteOutText(false);
    else
        iblock->setWriteOutText(true);

    // CLASS DECLARATION BLOCK
    //

    // get the declaration block. If it is not already present, add it too
    DClassDeclarationBlock * myClassDeclCodeBlock = getClassDecl();
    addTextBlock(myClassDeclCodeBlock); // note: wont add if already present

    // NOW create document in sections..
    // now we want to populate the body of our class
    // our layout is the following general groupings of code blocks:

    // start d classifier document

    // header comment

    // package code block

    // import code block

    // class declaration

    //   section:
    //   - class field declaration section comment
    //   - class field declarations (0+ codeblocks)

    //   section:
    //   - methods section comment

    //     sub-section: constructor ops
    //     - constructor method section comment
    //     - constructor methods (0+ codeblocks)

    //     sub-section: accessors
    //     - accessor method section comment
    //     - static accessor methods (0+ codeblocks)
    //     - non-static accessor methods (0+ codeblocks)

    //     sub-section: non-constructor ops
    //     - operation method section comment
    //     - operations (0+ codeblocks)

    // end class declaration

    // end d classifier document


    // Q: Why use the more complicated scheme of arranging code blocks within codeblocks?
    // A: This will allow us later to preserve the format of our document so that if
    //    codeblocks are added, they may be easily added in the correct place, rather than at
    //    the end of the document, or by using a difficult algorithm to find the location of
    //    the last appropriate code block sibling (which may not exist.. for example user adds
    //    a constructor operation, but there currently are no constructor code blocks
    //    within the document).

    //
    // * CLASS FIELD declaration section
    //

    // get/create the field declaration code block
    HierarchicalCodeBlock * fieldDeclBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("fieldsDecl"), QLatin1String("Fields"), 1);

    // Update the comment: we only set comment to appear under the following conditions
    CodeComment * fcomment = fieldDeclBlock->getComment();
    if (isInterface || (!forceDoc() && !hasClassFields()))
        fcomment->setWriteOutText(false);
    else
        fcomment->setWriteOutText(true);

    // now actually declare the fields within the appropriate HCodeBlock
    declareClassFields(staticAttribClassFields, fieldDeclBlock);
    declareClassFields(attribClassFields, fieldDeclBlock);
    declareClassFields(plainAssocClassFields, fieldDeclBlock);
    declareClassFields(aggregationClassFields, fieldDeclBlock);
    declareClassFields(compositionClassFields, fieldDeclBlock);

    //
    // METHODS section
    //

    // get/create the method codeblock
    HierarchicalCodeBlock * methodsBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("methodsBlock"), QLatin1String("Methods"), 1);

    // Update the section comment
    CodeComment * methodsComment = methodsBlock->getComment();
    // set conditions for showing this comment
    if (!forceDoc() && !hasClassFields() && !hasOperationMethods)
        methodsComment->setWriteOutText(false);
    else
        methodsComment->setWriteOutText(true);

    // METHODS sub-section : constructor methods
    //

    // get/create the constructor codeblock
    HierarchicalCodeBlock * constBlock = methodsBlock->getHierarchicalCodeBlock(QLatin1String("constructorMethods"), QLatin1String("Constructors"), 1);
    constructorBlock = constBlock; // record this codeblock for later, when operations are updated

    // special condiions for showing comment: only when autogenerateding empty constructors
    // Although, we *should* check for other constructor methods too
    CodeComment * constComment = constBlock->getComment();
    CodeGenerationPolicy *pol = UMLApp::app()->commonPolicy();
    if (!forceDoc() && (isInterface || !pol->getAutoGenerateConstructors()))
        constComment->setWriteOutText(false);
    else
        constComment->setWriteOutText(true);

    // add/get the empty constructor
    QString DClassName = getDClassName(c->name());
    QString emptyConstStatement = QLatin1String("public ")+DClassName+QLatin1String(" () { }");
    CodeBlockWithComments * emptyConstBlock =
        constBlock->addOrUpdateTaggedCodeBlockWithComments(QLatin1String("emptyconstructor"), emptyConstStatement, QLatin1String("Empty Constructor"), 1, false);
    // Now, as an additional condition we only show the empty constructor block
    // IF it was desired to be shown
    if (parentIsClass() && pol->getAutoGenerateConstructors())
        emptyConstBlock->setWriteOutText(true);
    else
        emptyConstBlock->setWriteOutText(false);

    // METHODS subsection : ACCESSOR METHODS
    //

    // get/create the accessor codeblock
    HierarchicalCodeBlock * accessorBlock = methodsBlock->getHierarchicalCodeBlock(QLatin1String("accessorMethods"), QLatin1String("Accessor Methods"), 1);

    // set conditions for showing section comment
    CodeComment * accessComment = accessorBlock->getComment();
    if (!forceDoc() && !hasClassFields())
        accessComment->setWriteOutText(false);
    else
        accessComment->setWriteOutText(true);

    // now, 2 sub-sub sections in accessor block
    // add/update accessor methods for attributes
    HierarchicalCodeBlock * staticAccessors = accessorBlock->getHierarchicalCodeBlock(QLatin1String("staticAccessorMethods"), QString(), 1);
    staticAccessors->getComment()->setWriteOutText(false); // never write block comment
    staticAccessors->addCodeClassFieldMethods(staticAttribClassFields);
    staticAccessors->addCodeClassFieldMethods(attribClassFields);

    // add/update accessor methods for associations
    HierarchicalCodeBlock * regularAccessors = accessorBlock->getHierarchicalCodeBlock(QLatin1String("regularAccessorMethods"), QString(), 1);
    regularAccessors->getComment()->setWriteOutText(false); // never write block comment
    regularAccessors->addCodeClassFieldMethods(plainAssocClassFields);
    regularAccessors->addCodeClassFieldMethods(aggregationClassFields);
    regularAccessors->addCodeClassFieldMethods(compositionClassFields);

    // METHODS subsection : Operation methods (which arent constructors)
    //

    // get/create the operations codeblock
    operationsBlock = methodsBlock->getHierarchicalCodeBlock(QLatin1String("operationMethods"), QLatin1String("Operations"), 1);

    // set conditions for showing section comment
    CodeComment * ocomment = operationsBlock->getComment();
    if (!forceDoc() && !hasOperationMethods)
        ocomment->setWriteOutText(false);
    else
        ocomment->setWriteOutText(true);

}