void FiberSelector::updatePresentRois()
{
    qDebug() << "updatePresentRois";
    int numBranches = Models::r()->rowCount( QModelIndex() );

    for ( int i = 0; i < numBranches; ++i )
    {
        QList<QVector<bool> >newBranch;
        QVector<bool>newLeaf( m_numLines );
        newBranch.push_back( newLeaf );
        m_branchfields.push_back( newLeaf );
        m_bitfields.push_back( newBranch );
        updateBox( m_bitfields.size() - 1, 0 );

        int leafCount = Models::r()->rowCount( createIndex( i, 0, 0 ) );

        for ( int k = 0; k < leafCount; ++k )
        {
            // inserted child roi
            QVector<bool>newLeaf( m_numLines );
            m_bitfields[i].push_back( newLeaf );
            updateBox( i, k + 1 );
        }
    }
}
void NonPdfCropping::createWidgets(QGraphicsScene &scene)
{
  const double MARGIN_PERCENT = 5.0;
  const int ZERO_WIDTH_IS_ALWAYS_VISIBLE = 0;

  int marginHor = scene.width()  * MARGIN_PERCENT / 100.0;
  int marginVer = scene.height() * MARGIN_PERCENT / 100.0;

  QRect box (scene.sceneRect().left() + marginHor,
             scene.sceneRect().top()  + marginVer,
             scene.sceneRect().width() - 2 * marginHor,
             scene.sceneRect().height() - 2 * marginVer);

  m_handleTL = new NonPdfFrameHandle (scene, m_view, box.topLeft()    , NON_PDF_CROPPING_LEFT   | NON_PDF_CROPPING_TOP    , *this, Z_HANDLE);
  m_handleTR = new NonPdfFrameHandle (scene, m_view, box.topRight()   , NON_PDF_CROPPING_RIGHT  | NON_PDF_CROPPING_TOP    , *this, Z_HANDLE);
  m_handleBR = new NonPdfFrameHandle (scene, m_view, box.bottomRight(), NON_PDF_CROPPING_RIGHT  | NON_PDF_CROPPING_BOTTOM , *this, Z_HANDLE);
  m_handleBL = new NonPdfFrameHandle (scene, m_view, box.bottomLeft() , NON_PDF_CROPPING_LEFT   | NON_PDF_CROPPING_BOTTOM , *this, Z_HANDLE);

  m_box = new QGraphicsRectItem;
  m_box->setZValue (Z_BOX);
  m_box->setPen (QPen (QBrush (Qt::gray), ZERO_WIDTH_IS_ALWAYS_VISIBLE));
  scene.addItem (m_box);

  updateBox ();
}
Ejemplo n.º 3
0
void CanvasLayout::setBox(const BoundingBox& allowedBox)
{
    m_parentBox = allowedBox;
    m_box->setParentBox(allowedBox);
    m_list.setBox(m_box->get());
    updateBox();
}
Ejemplo n.º 4
0
void ShiftTraceTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
  m_gadget = m_highlightedGadget;
  m_oldPos = m_startPos = pos;

  if (m_gadget == NoGadget) {
    int row = getViewer()->posToRow(e.m_pos, 5 * getPixelSize(), false);
    if (row >= 0) {
      int currentRow = getFrame();
      int index      = -1;
      if (m_row[0] >= 0 && row <= currentRow)
        index = 0;
      else if (m_row[1] >= 0 && row > currentRow)
        index = 1;
      if (index >= 0) {
        m_ghostIndex = index;
        updateBox();
      }
    }

    if (!e.isCtrlPressed()) {
      m_gadget = TranslateGadget;
      // m_curveStatus = NoCurve;
    }
  }
  invalidate();
}
Ejemplo n.º 5
0
int CanvasLayout::addObject(const std::shared_ptr<IObject>& obj)
{
    int id = m_nextID++;
    m_objects[id] = obj;
    m_list.addObject(obj);
    loadIfNeeded(m_box, obj.get());
    updateBox();
    return id;
}
Ejemplo n.º 6
0
void CanvasLayout::removeObjects(const std::vector<int>& ids)
{
    if (ids.empty())
        return;
    for (auto it = ids.begin(); it != ids.end(); ++it)
        removeObject(*it);
    refill();
    updateBox();
}
void FiberSelector::roiInserted( const QModelIndex &parent, int start, int end )
{
    //qDebug() << "roi inserted" << parent.row() << start << end;
    if ( parent.row() == -1 )
    {
        // inserted top level roi
        QList<QVector<bool> >newBranch;
        QVector<bool>newLeaf( m_numLines );
        newBranch.push_back( newLeaf );
        m_branchfields.push_back( newLeaf );
        m_bitfields.push_back( newBranch );
        updateBox( m_bitfields.size() - 1, 0 );
    }
    else
    {
        // inserted child roi
        QVector<bool>newLeaf( m_numLines );
        m_bitfields[parent.row()].push_back( newLeaf );
        updateBox( parent.row(), m_bitfields[parent.row()].size() - 1 );
    }
}
Ejemplo n.º 8
0
void CanvasLayout::insertObject(int id, const std::shared_ptr<IObject>& obj)
{
    if (id >= m_nextID) {
        m_nextID = id + 1;
        m_objects[id] = obj;
        m_list.addObject(obj);
        loadIfNeeded(m_box, obj.get());
        return;
    }
    m_objects[id] = obj;
    refill();
    loadIfNeeded(m_box, obj.get());
    updateBox();
}
Ejemplo n.º 9
0
void ShiftTraceTool::updateData()
{
	TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
	int row = TApp::instance()->getCurrentFrame()->getFrame();
	int col = TApp::instance()->getCurrentColumn()->getColumnIndex();
	TXshCell cell = xsh->getCell(row, col);
	m_box = TRectD();
	for (int i = 0; i < 2; i++)
		m_row[i] = -1;
	m_dpiAff = TAffine();

	// we must find the prev (m_row[0]) and next (m_row[1]) reference images
	// (either might not exist)
	// see also stage.cpp, StageBuilder::addCellWithOnionSkin

	if (cell.isEmpty()) {
		// current cell is empty. search for the prev ref img
		int r = row - 1;
		while (r >= 0 && xsh->getCell(r, col).getSimpleLevel() == 0)
			r--;
		if (r >= 0)
			m_row[0] = r;
		// else prev drawing doesn't exist : nothing to do
	} else {
		// current cell is not empty
		// search for prev ref img
		TXshSimpleLevel *sl = cell.getSimpleLevel();
		int r = row - 1;
		if (r >= 0) {
			TXshCell otherCell = xsh->getCell(r, col);
			if (otherCell.getSimpleLevel() == sl) {
				// find the span start
				while (r - 1 >= 0 && xsh->getCell(r - 1, col) == otherCell)
					r--;
				m_row[0] = r;
			}
		}

		// search for next ref img
		r = row + 1;
		while (xsh->getCell(r, col) == cell)
			r++;
		// first cell after the current span has the same level
		if (xsh->getCell(r, col).getSimpleLevel() == sl)
			m_row[1] = r;
	}
	updateBox();
}
Ejemplo n.º 10
0
void CanvasLayout::removeObjects(const std::vector<IObject*>& objs)
{
    if (objs.empty())
        return;
    if (objs.size() == 1)
        removeObject(objs.front());
    std::unordered_set<IObject*> objsToRemove(objs.begin(), objs.end());
    std::map<int, std::shared_ptr<IObject>> newObjMap;
    for (auto it = m_objects.begin(); it != m_objects.end(); ++it) {
        if (objsToRemove.count(it->second.get()) == 0)
            newObjMap[it->first] = it->second;
    }
    newObjMap.swap(m_objects);
    refill();
    updateBox();
}
Ejemplo n.º 11
0
void CanvasLayout::addObjects(const std::vector<std::shared_ptr<IObject>>& objects)
{
    if (objects.empty())
        return;

    for (const auto& obj : objects)
        m_objects[m_nextID++] = obj;

    refill();

    if (m_box->isValid()) {
        for (const auto& obj : objects)
            loadIfNeededNoCheck(m_box, obj.get());
    }
    updateBox();
}
void NonPdfCropping::moveBR (const QPointF &newPos,
                             const QPointF &oldPos)
{
  disableEventsWhileMovingAutomatically();

  double deltaX = newPos.x() - oldPos.x();
  double deltaY = newPos.y() - oldPos.y();

  m_handleBL->moveBy (0,
                      deltaY);
  m_handleTR->moveBy (deltaX,
                      0);

  enableEventsWhileMovingAutomatically();

  updateBox();
}
Ejemplo n.º 13
0
Dialog::Dialog(const Common::UString &conv, Creature &pc, Object &obj,
               Module &module, bool playHello) :
	_conv(conv), _pc(&pc), _object(&obj), _module(&module) {

	_object->setPCSpeaker(&pc);

	_dlg = new Aurora::DLGFile(conv, _object, true);
	_dlg->startConversation();

	_dlgBox = new DialogBox(kDialogWidth, kDialogHeight);

	updateBox();
	playSound(playHello);
	playAnimation();

	notifyResized(0, 0, WindowMan.getWindowWidth(), WindowMan.getWindowHeight());
}
Ejemplo n.º 14
0
void Dialog::checkPicked() {
	uint32 picked = _dlgBox->getPickedID();
	if (picked == Aurora::DLGFile::kInvalidLine)
		return;

	_dlg->pickReply(picked);
	if (_dlg->hasEnded()) {
		stopAnimation();
		return;
	}

	updateBox();
	playSound(false);
	playAnimation();

	// Update the highlighted reply
	mouseMove();
}
Ejemplo n.º 15
0
void Actor::update()
{
    if (!_currentCostume || !_room)
    {
        return;
    }
    
    if (_textFramesPending > 0 && _textFramesPending-- == 1)
    {
        setAnimation(_talkStopAnimation);
    }
    
    if (_walkNumFrames == 0)
    {
        _currentCostume->update(&_pos, _scale, _light);
        return;
    }
    
    ++_walkFrame;

    if (_walkFrame >= _walkNumFrames)
    {
        nextPoint();
        _light = static_cast<uint8_t>(_pos.x);
        _currentCostume->update(&_pos, _scale, _light);
        if (_path.empty())
        {
            return;
        }
    }

    auto &next = _path.front();
    SDL_Point distance;
    distance.x = next.x - _walkOrigin.x;
    distance.y = next.y - _walkOrigin.y;
    
    _pos.x = _walkOrigin.x + (distance.x * (_walkFrame / static_cast<float>(_walkNumFrames)));
    _pos.y = _walkOrigin.y + (distance.y * (_walkFrame / static_cast<float>(_walkNumFrames)));
    updateBox();
    _scale = _box->getScale(_pos.y);
    _light = static_cast<uint8_t>(_pos.x);
    _currentCostume->update(&_pos, _scale, _light);
}
void FiberSelector::roiChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight )
{
    if ( topLeft.row() == -1 ) return;
    //qDebug() << "roi changed" << topLeft.row() << topLeft.column() << topLeft.internalId();
    int branch = 0;
    int pos = 0;
    if ( topLeft.internalId() == -1 )
    {
        // top level box
        branch = topLeft.row();
    }
    else
    {
        // child box
        branch = topLeft.internalId();
        pos = topLeft.row() + 1;
    }
    updateBox( branch, pos );

}
Ejemplo n.º 17
0
void CanvasLayout::insertObjects(
    const std::map<int, std::shared_ptr<IObject>>& objects)
{
    if (objects.empty())
        return;

    if (m_objects.empty()) {
        m_objects = objects;
    } else {
        m_objects.insert(objects.begin(), objects.end());
    }

    m_nextID = std::max(m_nextID, objects.rbegin()->first + 1);
    refill();

    if (m_box->isValid()) {
        for (auto it = objects.begin(); it != objects.end(); ++it)
            loadIfNeededNoCheck(m_box, it->second.get());
    }
    updateBox();
}
bool TeImportRaster (TeLayer* layer, TeRaster* rasterIn, 
					 unsigned int bWidth, unsigned int bHeight,TeRasterParams::TeRasterCompressionMode compress,
					 const string& objectId, double dummy, bool useDummy,
					 TeRasterParams::TeRasterTilingType indext)
{	

	if (!layer || !rasterIn)
		return false;

	string objId;
	if (objectId.empty())
		objId = "O1";
	else
		objId = objectId;


	// check if there  is a raster geometry to be modified
	string tableGeo;
	TeRepresentation* repp = 0;
	repp = layer->getRepresentation(TeRASTER);
	if (!repp || !layer->raster(objId))	// layer doesn´t have any 
	{										// or the desired raster geometry
											// a new one should be created
		TeProjection* projIn = rasterIn->projection();	
		TeProjection* projOut = layer->projection();

		TeRasterParams parOut = rasterIn->params();		// parameters of the raster being created	
														// start with the same parameters as input raster
		
		parOut.setCompressionMode(compress);		// overwrites some parameters 
		parOut.nTilesInMemory_ = 0;					// according to the specified in the interface
		parOut.blockHeight_ = bHeight;
		parOut.blockWidth_ = bWidth;
		parOut.setDummy(dummy);
		parOut.useDummy_ = useDummy;
		parOut.tiling_type_ = indext;

		TeBox newBox = rasterIn->params().boundingBox();

		// if input raster has some rotation associated it has to be corrected 
		// during the importing
		if (parOut.dxI_ != 0. || parOut.dyJ_ != 0.)
		{
			parOut.boundingBoxResolution(newBox.x1_,newBox.y1_,newBox.x2_,newBox.y2_,parOut.resx_,parOut.resy_);
			parOut.dxI_= 0.0;							  
			parOut.dyJ_= 0.0;							 
			parOut.dxJ_ = 0.0;
			parOut.dyI_ = 0.0;	
		}
		
		bool diffProj = false;
		parOut.projection(projOut);
		if (projIn && projOut && !(*projIn == *projOut))
		{
			diffProj = true;
			TeBox boxIn = rasterIn->params().boundingBox();
			newBox = TeRemapBox (boxIn,projIn,projOut);
			parOut.resx_ = newBox.width()/parOut.ncols_;	// recalculates resolutions 
			parOut.resy_ = newBox.height()/parOut.nlines_;  // for the new projection
			parOut.boundingBoxResolution(newBox.x1_,newBox.y1_,newBox.x2_,newBox.y2_,parOut.resx_,parOut.resy_);
			newBox = parOut.box();
		}
	
		if (indext == TeRasterParams::TeExpansible)			// if mosaicable adjust box 
			parOut.resizeToTiling(newBox,bWidth,bHeight);	// to be cut in blocks of bWidth X bHeight (in projection units)

		parOut.decoderIdentifier_ = "DB";					// parameters of the decoder
		parOut.fileName_ = "RasterLayer" + Te2String(layer->id()) + "_R_" + objId;

		if (parOut.photometric_[0] == TeRasterParams::TePallete)
			parOut.lutName_ = parOut.fileName_ + "_LUT";

		if (!layer->addRasterGeometry(parOut,objId))		// creates the empty raster geometry
			return false;

		// create a decoder to raster in a TerraLib database 
		parOut.mode_ = 'w';
		TeDecoderDatabase *dbDecoder = new TeDecoderDatabase(parOut);
		dbDecoder->setDB(layer->database());

		// optimization: we don't need to go through remap routines.
		// just cut the input raster and save the tiles
		bool res=false;
		TeRasterParams parF;
		if (indext == TeRasterParams::TeNoExpansible && !diffProj)
		{
			int ntiles = (parOut.nlines_/parOut.blockHeight_)*(parOut.ncols_/parOut.blockWidth_);
			if(TeProgress::instance())
				TeProgress::instance()->setTotalSteps(ntiles);
			int count = 0;
			clock_t	ti, tf;
			int x=0, y=0, b, nb=parOut.nBands(),lx, ly;
			double val= parOut.dummy_[0];
			TeMemoryPage page(parOut.blockHeight_*parOut.blockWidth_,val,parOut.dataType_[0]);
			string index;
			ti = clock();
			while (y<parOut.nlines_)  // for each row of tiles
			{
				page.ulLin_ = y;
				x=0;
				while (x<parOut.ncols_)	// for each tile in a row
				{
					page.clear();
					page.ulCol_= x;
					for (b=0; b<nb; ++b)    // for each band;
					{
						for (ly=0; ly<parOut.blockHeight_; ++ly)
						{
							for (lx=0; lx<parOut.blockWidth_; ++lx)  // write the tile
							{
								if (rasterIn->getElement(x+lx,y+ly,val,b))
								{
									page.setVal(x+lx,y+ly,parOut.blockWidth_,val);
									if (val<parOut.vmin_[b])
										parOut.vmin_[b] = val;
									if (val>parOut.vmax_[b])
										parOut.vmax_[b] = val;
								}
							}
						}
						index = dbDecoder->codifyId(x,y,b,1,0);
						if (!dbDecoder->putRasterBlock(index,page.data_,page.pageSize()))
							res=false;
						page.clear();
					}
					x+= parOut.blockWidth_;
					++count;
					if(TeProgress::instance())
					{
						tf = clock();
						if (int((tf-ti)/CLOCKS_PER_SEC) > 3)
						{
							if (TeProgress::instance()->wasCancelled())
								break;
							TeProgress::instance()->setProgress(count);
							ti = tf;
						}
					}
				}
				y+= parOut.blockHeight_;
			}
			if (TeProgress::instance())
				TeProgress::instance()->reset();

			// atualizes the representation box in memory
			TeRepresentation* repp = layer->getRepresentation(TeRASTER);
			updateBox(repp->box_,parOut.box());
			repp->nCols_ = parOut.ncols_;
			repp->nLins_ = parOut.nlines_;
			repp->resX_ = parOut.resx_;
			repp->resY_ = parOut.resy_;
			layer->updateLayerBox(parOut.boundingBox());
			layer->database()->updateRasterRepresentation(layer->id(),dbDecoder->params(),objId);
			// atualizes representation in the database
			for (b=0; b<nb; ++b)
			{
				dbDecoder->params().vmax_[b]=parOut.vmax_[b];
				dbDecoder->params().vmin_[b]=parOut.vmin_[b];
			}
			layer->database()->updateRasterRepresentation(layer->id(),dbDecoder->params(),objId);
			dbDecoder->clear();
			res=true;
		}
		else
		{
			TeRaster* rasterOut = new TeRaster();
			rasterOut->setDecoder(dbDecoder);
			rasterOut->init();
			TeRasterRemap remap(rasterIn, rasterOut);
			if (remap.apply(true))
			{
				TeRepresentation* repp = layer->getRepresentation(TeRASTER);
				updateBox(repp->box_,rasterOut->params().box());
				repp->nCols_ = rasterOut->params().ncols_;
				repp->nLins_ = rasterOut->params().nlines_;
				repp->resX_ = rasterOut->params().resx_;
				repp->resY_ = rasterOut->params().resy_;

				// atualizes representation in the database
				layer->database()->updateRasterRepresentation(layer->id(),rasterOut->params(),objId);
				layer->updateLayerBox(rasterOut->params().boundingBox());
				rasterOut->clear();
				res = true;
			}
		}
		if (res)			
		{
			//	create spatial index in the block box
			string tableR = layer->database()->getRasterTable(layer->id(),objId);
			layer->database()->insertMetadata(tableR,layer->database()->getSpatialIdxColumn(TeRASTER), 0.000005,0.000005,layer->box());		
			layer->database()->createSpatialIndex(tableR,layer->database()->getSpatialIdxColumn(TeRASTER), (TeSpatialIndexType)TeRTREE);
		}
		delete dbDecoder;
		return res;
	}
	else
	{
		// layer contains already a raster representation associated to the
		// object id: calls mosaic operation
		return TeMosaicRaster(rasterIn,layer,objId);
	}
}
bool updateDB320To3201(TeDatabase* db, string& errorMessage)
{
	//--- remove the table te_color_scheme
	if(db->tableExist("te_color_scheme"))
	{
		db->deleteTable("te_color_scheme");
	}
	
	//--- store the theme box 
	//verify if the theme box is stored 
	TeAttribute	attr;
	attr.rep_.name_ = "lower_x";
	attr.rep_.type_ = TeREAL;

  //create the columns
	TeAttributeRep atRep;
	atRep.type_ = TeREAL;
	atRep.name_ = "lower_x";
	atRep.decimals_ = 15;
	atRep.defaultValue_ = "0.0";

	if(!db->columnExist("te_theme", attr.rep_.name_,attr))
	{
		if(db->addColumn("te_theme", atRep) == false)
		{
			errorMessage = "The theme box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	attr.rep_.name_ = "lower_y";
	if(!db->columnExist("te_theme", attr.rep_.name_,attr))
	{
		atRep.name_ = "lower_y";
		if(db->addColumn("te_theme", atRep) == false)
		{
			errorMessage = "The theme box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	attr.rep_.name_ = "upper_x";
	if(!db->columnExist("te_theme", attr.rep_.name_,attr))
	{
		atRep.name_ = "upper_x";
		if(db->addColumn("te_theme", atRep) == false)
		{
			errorMessage = "The theme box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	attr.rep_.name_ = "upper_y";
	if(!db->columnExist("te_theme", attr.rep_.name_,attr))
	{
		atRep.name_ = "upper_y";
		if(db->addColumn("te_theme", atRep) == false)
		{
			errorMessage = "The theme box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}

	//--- store the view box and current theme 
	//verify if the view box is stored 
	attr.rep_.name_ = "lower_x";
	attr.rep_.type_ = TeREAL;

	//create the columns
	if(!db->columnExist("te_view", attr.rep_.name_,attr))
	{
		atRep.type_ = TeREAL;
		atRep.name_ = "lower_x";
		atRep.decimals_ = 15;
		atRep.defaultValue_ = "0.0";
		if(db->addColumn("te_view", atRep) == false)
		{
			//delete portal;
			errorMessage = "The view box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	attr.rep_.name_ = "lower_y";
	if(!db->columnExist("te_view", attr.rep_.name_,attr))
	{
		atRep.name_ = "lower_y";
		if(db->addColumn("te_view", atRep) == false)
		{
			//delete portal;
			errorMessage = "The view box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	attr.rep_.name_ = "upper_x";
	if(!db->columnExist("te_view", attr.rep_.name_,attr))
	{
		atRep.name_ = "upper_x";
		if(db->addColumn("te_view", atRep) == false)
		{
			//delete portal;
			errorMessage = "The view box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	attr.rep_.name_ = "upper_y";
	if(!db->columnExist("te_view", attr.rep_.name_,attr))
	{
		atRep.name_ = "upper_y";
		if(db->addColumn("te_view", atRep) == false)
		{
			//delete portal;
			errorMessage = "The view box could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}
	atRep.type_ = TeINT;
	atRep.name_ = "current_theme";
	atRep.decimals_ = 0;
	attr.rep_.name_ = "current_theme";
	if(!db->columnExist("te_view", attr.rep_.name_,attr))
	{
		if(db->addColumn("te_view", atRep) == false)
		{
			//delete portal;
			errorMessage = "The view current theme could not be appended!\n";
			errorMessage += db->errorMessage();
			return false;
		}
		//create foreign key
		if (!db->createRelation("fk_view_current_theme", "te_view", "current_theme", "te_theme", "theme_id", false))
		{
			//delete portal;
			errorMessage = "Error creating foreign key in the view table!\n";
			errorMessage += db->errorMessage();
			return false;
		}
	}

	//fill the box theme
	string sql = "SELECT te_theme.name, te_view.user_name ";
	sql += " FROM te_theme INNER JOIN te_view ON te_theme.view_id = te_view.view_id ";
	TeDatabasePortal* portal = db->getPortal();
	if(!portal)
		return false;
	
	if(!portal->query(sql))
	{
		delete portal;
		return false;
	}

	string originalUser = db->user();
	while(portal->fetchRow())
	{
		string themeName = string(portal->getData(0));
		string userName = string(portal->getData(1));
		db->user(userName);

		TeTheme theme(themeName);
		if(!db->loadTheme(&theme))
		{
			delete portal;
			errorMessage = "Error updating theme box!";
			return false;
		}

		if(theme.type()==TeTREE)
			continue;

		//select the theme box
		TeBox bb;
		if (theme.layer()->hasGeometry(TeRASTER))
			bb = theme.layer()->box();

		if (theme.layer()->hasGeometry(TeRASTERFILE))
			updateBox(bb,theme.layer()->getRepresentation(TeRASTERFILE)->box_);

		string colTabName = theme.collectionTable();
		if (!colTabName.empty())
		{
			string sqlfrom;
			string geomTable;
			if (theme.layer()->hasGeometry(TePOINTS))
			{
				geomTable = theme.layer()->tableName(TePOINTS);
				sqlfrom = colTabName + " LEFT JOIN " + geomTable;
				sqlfrom += " ON " + colTabName + ".c_object_id = " + geomTable + ".object_id";
				TeBox bpt;
				if(db->getMBRSelectedObjects(geomTable,"spatial_data", sqlfrom, "","",TePOINTS,bpt))
					updateBox(bb,bpt);
			}
			if (theme.layer()->hasGeometry(TeLINES))
			{
				geomTable = theme.layer()->tableName(TeLINES);
				sqlfrom = colTabName + " LEFT JOIN " + geomTable;
				sqlfrom += " ON " + colTabName + ".c_object_id = " + geomTable + ".object_id";
				TeBox bln;
				if (db->getMBRSelectedObjects(geomTable,"spatial_data", sqlfrom, "","",TeLINES,bln))
					updateBox(bb,bln);
			}
			if (theme.layer()->hasGeometry(TePOLYGONS))
			{
				geomTable = theme.layer()->tableName(TePOLYGONS);
				sqlfrom = colTabName + " LEFT JOIN " + geomTable;
				sqlfrom += " ON " + colTabName + ".c_object_id = " + geomTable + ".object_id";
				TeBox bpol;
				if (db->getMBRSelectedObjects(geomTable,"spatial_data", sqlfrom, "","",TePOLYGONS,bpol))
					updateBox(bb,bpol);
			}

			if (theme.layer()->hasGeometry(TeCELLS))
			{
				geomTable = theme.layer()->tableName(TeCELLS);
				sqlfrom = colTabName + " LEFT JOIN " + geomTable;
				sqlfrom += " ON " + colTabName + ".c_object_id = " + geomTable + ".object_id";
				TeBox bpol;
				if (db->getMBRSelectedObjects(geomTable,"spatial_data", sqlfrom, "","",TeCELLS,bpol))
					updateBox(bb,bpol);
			}

			if (theme.layer()->hasGeometry(TeTEXT))
			{
				geomTable = theme.layer()->tableName(TeTEXT);
				sqlfrom = colTabName + " LEFT JOIN " + geomTable;
				sqlfrom += " ON " + colTabName + ".c_object_id = " + geomTable + ".object_id";
				TeBox bpol;
				if (db->getMBRSelectedObjects(geomTable,"spatial_data", sqlfrom, "","",TeTEXT,bpol))
					updateBox(bb,bpol);
			}	
		}
					
		//update theme box
		string update = "UPDATE te_theme SET ";
		update += "  lower_x = " + Te2String(bb.x1()); 
		update += ", lower_y = " + Te2String(bb.y1()); 
		update += ", upper_x = " + Te2String(bb.x2()); 
		update += ", upper_y = " + Te2String(bb.y2()); 
		update += " WHERE theme_id=" + Te2String (theme.id());
		if(!db->execute(update))
		{
			delete portal;
			errorMessage = "Error updating theme box!\n";
			errorMessage += db->errorMessage();
			return false;
		}
    }

	db->clear();
	portal->freeResult();
	db->user(originalUser);

	//fill the box view
	sql = "SELECT view_id, MIN(lower_x), MIN(lower_y), MAX(upper_x), MAX(upper_y) ";
	sql += " FROM te_theme GROUP BY view_id ";
	
	if(!portal->query(sql))
	{
		delete portal;
		return false;
	}

	while(portal->fetchRow())
	{
		string viewId = string(portal->getData(0));
		string update = " UPDATE te_view SET ";
		update += " lower_x = "+ string(portal->getData(1));
		update += ", lower_y = "+ string(portal->getData(2));
		update += ", upper_x = "+ string(portal->getData(3));
		update += ", upper_y = "+ string(portal->getData(4));
		update += ", current_theme = NULL ";
		update += " WHERE view_id = "+ viewId;

		if(!db->execute(update))
		{
			delete portal;
			errorMessage = "Error updating view box!\n";
			errorMessage += db->errorMessage();
			return false;
		}
    }

	//------ Project information
	attr.rep_.name_ = "current_view";
	attr.rep_.type_ = TeINT;

	//if there is the column "current_view", delete it and create it again 
	if(db->columnExist("te_project", attr.rep_.name_, attr))
		db->deleteColumn("te_project", attr.rep_.name_);
	
	attr.rep_.defaultValue_ = "0";
	if(!db->addColumn("te_project", attr.rep_))
	{
		delete portal;
		errorMessage = "The project view could not be appended!\n";
		errorMessage += db->errorMessage();
		return false;
	}
	
	TeProject project;
	project.setName("TV_Project");
	project.setDescription("TerraView_Default_Project");
	project.setCurrentViewId(-1); // not have project
	if(!db->insertProject(&project))
	{
		delete portal;
		errorMessage = "Error inserting terraView default project!\n";
		errorMessage += db->errorMessage();
		return false;
	}

	portal->freeResult();
	if(!portal->query("SELECT view_id FROM te_view"))
	{
		errorMessage = db->errorMessage();
		delete portal;
		return false;
	}
	while(portal->fetchRow())
	{
		string viewId = string(portal->getData(0));
		string ins = "INSERT INTO te_project_view (project_id, view_id) VALUES (";
		ins += Te2String(project.id()) +  "," + viewId + ")";
		if(!db->execute(ins))
		{
			errorMessage = db->errorMessage();
			delete portal;
			return false;
		}
	}

	delete portal;
	return true;
}
// This function mosaics an input raster to one previsously existing in a TerraLib layer
bool TeMosaicRaster(TeRaster* rasterIn, TeLayer* layer,  const string& objectId)
{

	// layer must exist and input raster should be read to be read
	if (!layer || !rasterIn  || rasterIn->params().status_ != TeRasterParams::TeReadyToRead)
		return false;
	
	TeRaster* rasterOut;
	if (!objectId.empty())	// if object id informed try to get raster associated to it
		rasterOut = layer->raster(objectId,'w');
	else					// else try to get first one found
		rasterOut = layer->raster();

	if (!rasterOut)			// no raster asked or no raster at all
		return false;				// can not do mosaic

	if (rasterOut->params().tiling_type_==TeRasterParams::TeNoExpansible)
		return false;				// can mosaic if is not possible

	// allows mosaic of same photometric types only
	if (rasterOut->params().photometric_[0] != rasterIn->params().photometric_[0])
		return false;

	// increases output box to: input raster box + output raster box 
  TeBox boxIn = rasterIn->params().boundingBox();

	// if necessary remap input box to output projection 
	if (!(*(rasterIn->projection()) == *(rasterOut->projection())))
		boxIn = TeRemapBox(boxIn,rasterIn->projection(),rasterOut->projection());

	// sum stored and input boxes
	TeBox newBoxa = rasterOut->params().boundingBox();
	updateBox(newBoxa,boxIn);	
  
  // adjust it to expansible values
	TeBox newBox = adjustToCut(newBoxa, rasterOut->params().blockWidth_*rasterOut->params().resx_, 
							   rasterOut->params().blockHeight_*rasterOut->params().resy_);

	// update box in parameters of the raster and it's decoder
	rasterOut->params().boundingBoxResolution(newBox.x1_,newBox.y1_,newBox.x2_,newBox.y2_,
											  rasterOut->params().resx_, rasterOut->params().resy_);

	rasterOut->decoder()->params().boundingBoxResolution(newBox.x1_,newBox.y1_,newBox.x2_,newBox.y2_,
											  rasterOut->params().resx_, rasterOut->params().resy_);
	rasterOut->params().nTilesInMemory_ = 0;
	
	// creates a remapping from input raster to output raster
	TeRasterRemap remap(rasterIn, rasterOut);
	if (remap.apply(true))			// o.k.
	{
		TeRasterParams rp = rasterOut->params();

		// atualizes the representation box in memory
		TeRepresentation* repp = layer->getRepresentation(TeRASTER);
		TeBox boxNew = rp.box();
		updateBox(repp->box_,rp.box());
		repp->nCols_ = rp.ncols_;
		repp->nLins_ = rp.nlines_;
		repp->resX_ = rp.resx_;
		repp->resY_ = rp.resy_;

		// atualizes representation in the database
		layer->database()->updateRasterRepresentation(layer->id(),rp,objectId);
		layer->updateLayerBox(rp.boundingBox());
		rasterOut->clear();
		return true;
	}
	return false;
}
Ejemplo n.º 21
0
void Hero::updateAllBox(){
    updateBox(m_bodyBox);
    updateBox(m_attackBox);
    updateBox(m_talkingBox);
}
Ejemplo n.º 22
0
void CRockmanBullet::update(CGameTime* gametime)
{
	_position += _v*gametime->getDeltaTime();
	updateBox();
}
Ejemplo n.º 23
0
void CanvasLayout::removeObject(int id)
{
    m_objects.erase(id);
    refill();
    updateBox();
}