示例#1
0
文件: DBNetMisc.C 项目: rjs80/RGIS
int DBNetworkIF::Trim ()

	{
	DBInt i, row, col;
	DBPosition pos, min, max;
	DBRegion extent = DataPTR->Extent ();
	DBObjRecord *cellRec;
	DBCoordinate coord;

	min.Row = RowNum ();
	min.Col = ColNum ();
	max.Row = max.Col = 0;

	for (i = 0;i < CellNum ();++i)
		{
		DBPause (33 * i / CellNum ());
		cellRec = CellTable->Item (i);
		pos = CellPosition (cellRec);
		min.Row = min.Row < pos.Row ? min.Row : pos.Row;
		min.Col = min.Col < pos.Col ? min.Col : pos.Col;
		max.Row = max.Row > pos.Row ? max.Row : pos.Row;
		max.Col = max.Col > pos.Col ? max.Col : pos.Col;
		}

	for (i = 0;i < CellNum ();++i)
		{
		DBPause (33 + 33 * i / CellNum ());
		cellRec = CellTable->Item (i);
		pos = CellPosition (cellRec);
		pos.Row = pos.Row - min.Row;
		pos.Col = pos.Col - min.Col;
		PositionFLD->Position (cellRec,pos);
		}
	coord.X = min.Col * CellWidth ();
	coord.Y = min.Row * CellHeight ();
	extent.LowerLeft = extent.LowerLeft + coord;
	coord.X = (ColNum () - max.Col - 1) * CellWidth ();
	coord.Y = (RowNum () - max.Row - 1) * CellHeight ();
	extent.UpperRight = extent.UpperRight - coord;
	DataPTR->Extent (extent);

	row = max.Row - min.Row + 1;
	col = max.Col - min.Col + 1;
	RowNumFLD->Int (LayerRecord,row);
	ColNumFLD->Int (LayerRecord,col);

	DataRec->Realloc (row * col * sizeof (int));

	for (row = 0;row < RowNum ();row++)	for (col = 0;col < ColNum ();col++)
			((DBInt *) DataRec->Data ()) [row * ColNum () + col] = DBFault;

	for (i = 0;i < CellNum ();++i)
		{
		DBPause (67 + 33 * i / CellNum ());
		pos = CellPosition (CellTable->Item (i));
		((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID ();
		}

	return (DBSuccess);
	}
示例#2
0
文件: DBNetMisc.C 项目: rjs80/RGIS
DBCoordinate DBNetworkIF::Center (const DBObjRecord *cellRec) const
	{
	DBCoordinate coord;
	DBPosition cellPos = PositionFLD->Position (cellRec);

	coord.X = DataPTR->Extent ().LowerLeft.X + cellPos.Col * CellWidth  () + CellWidth  () / 2.0;
	coord.Y = DataPTR->Extent ().LowerLeft.Y + cellPos.Row * CellHeight () + CellHeight () / 2.0;
	return (coord);
	}
示例#3
0
DBFloat DBGridIF::CellArea(DBPosition pos) const {
    DBCoordinate coord0, coord1;

    coord0.X = DataPTR->Extent().LowerLeft.X + pos.Col * CellWidth();
    coord0.Y = DataPTR->Extent().LowerLeft.Y + pos.Row * CellHeight();
    coord1.X = DataPTR->Extent().LowerLeft.X + pos.Col * CellWidth() + CellWidth();
    coord1.Y = DataPTR->Extent().LowerLeft.Y + pos.Row * CellHeight() + CellHeight();

    return (DBMathRectangleArea(DataPTR->Projection(), coord0, coord1));
}
示例#4
0
DBInt DBGridIF::Pos2Coord(DBPosition pos, DBCoordinate &coord) const {
    DBInt ret = DBSuccess;
    if (pos.Col < 0) ret = DBFault;
    if (pos.Row < 0) ret = DBFault;
    if (pos.Col >= ColNum()) ret = DBFault;
    if (pos.Row >= RowNum()) ret = DBFault;

    coord.X = DataPTR->Extent().LowerLeft.X + pos.Col * CellWidth() + CellWidth() / 2.0;
    coord.Y = DataPTR->Extent().LowerLeft.Y + pos.Row * CellHeight() + CellHeight() / 2.0;
    return (ret);
}
示例#5
0
DBInt DBGridIF::Coord2Pos(DBCoordinate coord, DBPosition &pos) const {
    pos.Col = (DBInt) floor((coord.X - DataPTR->Extent().LowerLeft.X) / CellWidth());
    pos.Row = (DBInt) floor((coord.Y - DataPTR->Extent().LowerLeft.Y) / CellHeight());
    if ((pos.Col < 0) || (pos.Col >= ColNum())) return (DBFault);
    if ((pos.Row < 0) || (pos.Row >= RowNum())) return (DBFault);
    return (DBSuccess);
}
void NodesPropertyControl::OnMinus(BaseObject * , void * , void * )
{
    if(propControl->GetParent() || listHolder->GetParent())
    {
        return;
    }
    
    if(currentSceneNode)
    {
        KeyedArchive *customProperties = currentSceneNode->GetCustomProperties();
        Map<String, VariantType*> propsData = customProperties->GetArchieveData();
        
        int32 size = propsData.size();
        if(size)
        {
            Rect r = listHolder->GetRect();
            r.dy = Min(r.dy, (float32)size * CellHeight(NULL, 0));
            r.y = listHolder->GetRect().dy - r.dy - ControlsFactory::BUTTON_HEIGHT;
            
            deletionList = new UIList(r, UIList::ORIENTATION_VERTICAL);
            ControlsFactory::SetScrollbar(deletionList);
            ControlsFactory::CustomizePropertyCell(deletionList, false);
            
            deletionList->SetDelegate(this);
            
            listHolder->AddControl(deletionList);
            deletionList->Refresh();
            AddControl(listHolder);
        }
    }
}
示例#7
0
文件: DBNetMisc.C 项目: rjs80/RGIS
DBInt DBNetworkIF::Coord2Pos (DBCoordinate coord,DBPosition &pos) const

	{
	DBInt ret = DataPTR->Extent ().InRegion (coord) ? DBSuccess : DBFault;

 	pos.Col = (DBUShort) floor ((coord.X - DataPTR->Extent ().LowerLeft.X ) / CellWidth ());
	pos.Row = (DBUShort) floor ((coord.Y - DataPTR->Extent ().LowerLeft.Y ) / CellHeight ());
	return (ret);
	}
示例#8
0
文件: DBNetMisc.C 项目: rjs80/RGIS
DBCoordinate DBNetworkIF::Delta (const DBObjRecord *cellRec) const
	{
	DBInt toCell = ToCellFLD->Int (cellRec);
	DBCoordinate delta (0.0, 0.0);

	if ((toCell == DBNetDirNW) || (toCell == DBNetDirN) || (toCell == DBNetDirNE)) delta.Y =   CellHeight ();
	if ((toCell == DBNetDirSE) || (toCell == DBNetDirS) || (toCell == DBNetDirSW)) delta.Y = - CellHeight ();
	if ((toCell == DBNetDirNE) || (toCell == DBNetDirE) || (toCell == DBNetDirSE)) delta.X =   CellWidth ();
	if ((toCell == DBNetDirNW) || (toCell == DBNetDirW) || (toCell == DBNetDirSW)) delta.X = - CellWidth ();
	return (delta);
	}
示例#9
0
DBInt DBGridIF::Value(DBObjRecord *layerRec, DBCoordinate coord, DBFloat *value) const {
    DBInt i, j, pointNum;
    DBInt row[9], col[9];
    DBPosition pos;
    DBCoordinate cellCoord;
    DBPosition cellPos;
    DBFloat precision, dist, wAvg, sumWeight, retVal;
    DBObjRecord *dataRec = LayerFLD->Record(layerRec);
    DBFloat missingValue = MissingValueFLD->Float(ItemTable->Item());
    DBMathDistanceFunction distFunc = DBMathGetDistanceFunction(DataPTR);

    if (DataPTR->Extent().InRegion(coord) == false) return (false);
    precision = pow((double) 10.0, (double) DataPTR->Precision());
    Coord2Pos(coord, cellPos);
    Pos2Coord(cellPos, cellCoord);
    if (Flat ||
        ((fabs(coord.X - cellCoord.X) < precision) &&
         (fabs(coord.Y - cellCoord.Y) < precision))) {
        j = DimensionVAR.Col * (DimensionVAR.Row - cellPos.Row - 1) + cellPos.Col;
        switch (ValueTypeVAR) {
            case DBTableFieldFloat:
                switch (ValueSizeVAR) {
                    case sizeof(DBFloat4):
                        retVal = (DBFloat) ((DBFloat4 *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBFloat):
                        retVal = (DBFloat) ((DBFloat *) (dataRec->Data()))[j];
                        break;
                }
                break;
            case DBTableFieldInt:
                switch (ValueSizeVAR) {
                    case sizeof(DBByte):
                        retVal = (DBFloat) ((DBByte *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBShort):
                        retVal = (DBFloat) ((DBShort *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBInt):
                        retVal = (DBFloat) ((DBInt *) (dataRec->Data()))[j];
                        break;
                }
                break;
        }
        if (!CMmathEqualValues(retVal, missingValue)) {
            *value = retVal;
            return (true);
        }
    }
    col[0] = cellPos.Col;
    row[0] = cellPos.Row;
    if (coord.X < cellCoord.X) col[0] -= 1;
    if (coord.Y < cellCoord.Y) row[0] -= 1;
    col[1] = col[0] + 1;
    row[1] = row[0];
    col[2] = col[0] + 1;
    row[2] = row[0] + 1;
    col[3] = col[0];
    row[3] = row[0] + 1;

    pos.Col = col[0];
    pos.Row = row[0];
    Pos2Coord(pos, cellCoord);
    if ((coord.X - cellCoord.X) > (3.0 * CellWidth() / 4.0)) i = 1;
    else if ((coord.X - cellCoord.X) > (CellWidth() / 4.0)) i = 0;
    else i = -1;
    if ((coord.Y - cellCoord.Y) > (3.0 * CellHeight() / 4.0)) j = 1;
    else if ((coord.Y - cellCoord.Y) > (CellHeight() / 4.0)) j = 0;
    else j = -1;

    if ((i != 0) || (j != 0)) {
        if (i == 0) {
            row[4] = row[5] = j > 0 ? row[2] + 1 : row[0] - 1;
            col[4] = col[0];
            col[5] = col[2];
            pointNum = 6;
        }
        else if (j == 0) {
            row[4] = row[0];
            row[5] = row[2];
            col[4] = col[5] = i > 0 ? col[2] + 1 : col[0] - 1;
            pointNum = 6;
        }
        else {
            row[7] = row[0];
            row[8] = row[2];
            if (j > 0)
                row[4] = row[5] = row[6] = row[2] + 1;
            else
                row[4] = row[5] = row[6] = row[0] - 1;

            if (i > 0) {
                col[4] = col[0];
                col[5] = col[2];
                col[6] = col[7] = col[8] = col[2] + 1;
            }
            else {
                col[5] = col[0];
                col[6] = col[2];
                col[4] = col[7] = col[8] = col[0] - 1;
            }
            pointNum = 9;
        }
    }
    else pointNum = 4;

    wAvg = sumWeight = 0.0;
    for (i = 0; i < pointNum; ++i) {
        if (col[i] < 0) continue;
        if (row[i] < 0) continue;
        if (col[i] >= DimensionVAR.Col) continue;
        if (row[i] >= DimensionVAR.Row) continue;

        j = DimensionVAR.Col * (DimensionVAR.Row - row[i] - 1) + col[i];
        switch (ValueTypeVAR) {
            case DBTableFieldFloat:
                switch (ValueSizeVAR) {
                    case sizeof(DBFloat4):
                        retVal = (DBFloat) ((DBFloat4 *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBFloat):
                        retVal = (DBFloat) ((DBFloat *) (dataRec->Data()))[j];
                        break;
                }
                break;
            case DBTableFieldInt:
                switch (ValueSizeVAR) {
                    case sizeof(DBByte):
                        retVal = (DBFloat) ((DBByte *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBShort):
                        retVal = (DBFloat) ((DBShort *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBInt):
                        retVal = (DBFloat) ((DBInt *) (dataRec->Data()))[j];
                        break;
                }
                break;
        }
        if (CMmathEqualValues(retVal, missingValue)) {
            if ((col[i] == cellPos.Col) && (row[i] == cellPos.Row)) return (false);
            else continue;
        }
        pos.Row = (DBUShort) row[i];
        pos.Col = (DBUShort) col[i];
        Pos2Coord(pos, cellCoord);
        if (pointNum > 1) {
            dist = DBMathCoordinateDistance(distFunc, coord, cellCoord);
            dist *= dist;
        }
        else dist = 1.0;
        wAvg = wAvg + retVal / dist;
        sumWeight = sumWeight + 1.0 / dist;
    }
    if (sumWeight > 0) {
        *value = wAvg / sumWeight;
        return (true);
    }
    else {
        *value = missingValue;
        return (false);
    }
}
示例#10
0
		DBInt Write (FILE *file,DBObjData *data)
			{
			char *dmRecord;
			DBInt layerID, docLen, dbType, intVal;
			DBFloat floatVal;
			DBPosition pos;
			DBObjRecord *layerRec;
			DBGridIF *gridIF = new DBGridIF (data);
			DMLayerHeader dmLayerHeader;

			dbType = gridIF->ValueType ();
			switch (dbType)
				{
				case DBTableFieldFloat: DataType (DMFloat);	break;
				case DBTableFieldInt:
					DataType (gridIF->ValueSize () > 1 ? DMInt : DMByte); 	break;
				}
			CellWidth (gridIF->CellWidth ());
			CellHeight (gridIF->CellHeight ());
			Extent (data->Extent ());
			LayerNum (gridIF->LayerNum ());
			RowNum (gridIF->RowNum ());
			ColNum (gridIF->ColNum ());
			dmRecord = (char *) calloc (RowNum () * ColNum (),DataType () != DMByte ? sizeof (int) : sizeof (char));
			if (dmRecord == (char *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }

			DMFileHeader::Write (file);
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				dmLayerHeader.Description (layerRec->Name ());
				dmLayerHeader.Write (file);
				}
			docLen = strlen (data->Document (DBDocComment));
			if (fwrite (&docLen,sizeof (int),1,file) != 1)
				{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (docLen > 0)
				{
				if (fwrite (data->Document (DBDocComment),docLen,1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				}
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				switch (data->Type ())
					{
					case DBTypeGridContinuous:
						layerRec = gridIF->Layer (layerID);
						if (dbType == DBTableFieldFloat)
							{
							for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
								for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
									if (gridIF->Value (layerRec,pos,&floatVal))
										((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (float) floatVal;
									else
										((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = MissingValue ();
							}
						else
							{
							for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
								for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
									if (gridIF->Value (layerRec,pos,&intVal))
										{
										if (DataType () == DMInt)
											((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) intVal;
										else
											dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
										}
									else
										{
										if (DataType () == DMInt)
											((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) MissingValue ();
										else
											dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;
										}

							}
						break;
					case DBTypeGridDiscrete:
						for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
							for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
								{
								intVal = gridIF->GridValue (layerRec,pos);
								if (DataType () == DMInt)
									((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
								else
									dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;

								}
						break;
					default:
						CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__);
						free (dmRecord);
						delete gridIF;
						return (DBFault);
					}
				if ((DBInt) fwrite (dmRecord,DataType () == DMByte ? sizeof (char) : sizeof (int),DataPointNum (),file) != DataPointNum ())
					{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				}
			free (dmRecord);
			delete gridIF;
			return (DBSuccess);
			}
示例#11
0
		DBInt Read (FILE *file,DBObjData *data)
			{
			DBInt i, layer, swap, valueType, valueSize, docLength;
			DMLayerHeader dmLayerHeader;
			DBObjRecord *layerRec, *dataRec;
			DBObjTable *layerTable = data->Table (DBrNLayers);
			DBObjTable *itemTable	 = data->Table (DBrNItems);
			DBObjTableField *rowNumFLD = layerTable->Field (DBrNRowNum);
			DBObjTableField *colNumFLD = layerTable->Field (DBrNColNum);
			DBObjTableField *cellWidthFLD = layerTable->Field (DBrNCellWidth);
			DBObjTableField *cellHeightFLD = layerTable->Field (DBrNCellHeight);
			DBObjTableField *valueTypeFLD = layerTable->Field (DBrNValueType);
			DBObjTableField *valueSizeFLD = layerTable->Field (DBrNValueSize);
			DBObjTableField *layerFLD = layerTable->Field (DBrNLayer);
			DBGridIF *gridIF;

			if ((swap = DMFileHeader::Read (file)) == DBFault) return (DBFault);
         data->Extent (Extent ());
         data->Projection (DBMathGuessProjection (data->Extent ()));
         data->Precision  (DBMathGuessPrecision  (data->Extent ()));
			if (FileType () != DMMatrix)
				{ CMmsgPrint (CMmsgAppError, "Wrong File Type in: %s %d",__FILE__,__LINE__); return (DBFault); }
			switch (DataType ())
				{
				case DMFloat:	valueType = DBTableFieldFloat;	valueSize = sizeof (DBFloat4);break;
				case DMInt:		valueType = DBTableFieldInt;		valueSize = sizeof (DBInt);	break;
				case DMByte:	valueType = DBTableFieldInt;		valueSize = sizeof (DBByte);	break;
				default: CMmsgPrint (CMmsgAppError, "Wrong Data Value Type in: %s %d",__FILE__,__LINE__); return (DBFault);
				}
			for (layer = 0;layer < LayerNum ();++layer)
				{
				if (dmLayerHeader.Read (file,swap) == DBFault) return (DBFault);
				if (strlen (dmLayerHeader.Description ()) > 0) layerName = dmLayerHeader.Description ();
				else { sprintf (layerNameSTR,"GHAASLayer%4d",layer + 1); layerName = layerNameSTR; }
				layerTable->Add (layerName);
				if ((layerRec = layerTable->Item ()) == (DBObjRecord *) NULL) return (DBFault);
				rowNumFLD->Int (layerRec,RowNum ());
				colNumFLD->Int (layerRec,ColNum ());
				cellWidthFLD->Float (layerRec,CellWidth ());
				cellHeightFLD->Float (layerRec,CellHeight ());
				valueTypeFLD->Int (layerRec,((DBInt) DBTypeGridDiscrete) == data->Type () ? DBTableFieldInt : valueType);
				valueSizeFLD->Int (layerRec,valueSize);
				if ((dataRec = new DBObjRecord (layerName,((size_t) ColNum ()) * RowNum () * valueSize,valueSize)) == (DBObjRecord *) NULL)
					return (DBFault);
				(data->Arrays ())->Add (dataRec);
				layerFLD->Record (layerRec,dataRec);
				}
			if (fread (&docLength,sizeof (int),1,file) != 1)
				{ CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (swap) DBByteOrderSwapWord (&docLength);
			if (docLength > 0)
				{
				char *docString;
				if ((docString = (char *) calloc (docLength,sizeof (char))) == (char *) NULL)
					{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				if (fread (docString,docLength,1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				data->Document (DBDocComment,docString);
				free (docString);
				}
			for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
				if (fread (dataRec->Data (),ColNum () * valueSize * RowNum (),1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (swap && valueSize > 1)
				{
				int i;
				void (*swapFunc) (void *);
				switch (valueSize)
					{
					case 2: swapFunc = DBByteOrderSwapHalfWord; break;
					case 4: swapFunc = DBByteOrderSwapWord; break;
					case 8: swapFunc = DBByteOrderSwapLongWord; break;
					default: CMmsgPrint (CMmsgAppError, "Wrong Data Value Size in: %s %d",__FILE__,__LINE__); return (DBFault);
					}
				for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
					for (i = 0;i < ColNum () * RowNum ();++i) (*swapFunc) ((char *) dataRec->Data () + i * valueSize);
				}
			switch (data->Type ())
				{
				case DBTypeGridDiscrete:
					{
					DBInt value;
					char nameStr [DBStringLength];
					DBObjRecord *symRec = (data->Table (DBrNSymbols))->Add ("Default Symbol");
					DBObjRecord *itemRec;
					DBObjTableField *gridValueFLD  = itemTable->Field (DBrNGridValue);
					DBObjTableField *gridSymbolFLD = itemTable->Field (DBrNSymbol);
					DBObjTableField *symbolIDFLD	 = (data->Table (DBrNSymbols))->Field (DBrNSymbolID);
					DBObjTableField *foregroundFLD = (data->Table (DBrNSymbols))->Field (DBrNForeground);
					DBObjTableField *backgroundFLD = (data->Table (DBrNSymbols))->Field (DBrNBackground);
					DBObjTableField *styleFLD = (data->Table (DBrNSymbols))->Field (DBrNStyle);

					symbolIDFLD->Int (symRec,0);
					foregroundFLD->Int (symRec,1);
					backgroundFLD->Int (symRec,0);
					styleFLD->Int (symRec,0);
					for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
						{
						for (i = 0;i < ColNum () * RowNum ();++i)
							{
							switch (valueType)
								{
								case DBTableFieldFloat: value = (DBInt) rint (*((float *) ((char *) dataRec->Data () + i * valueSize))); break;
								case DBTableFieldInt:
									switch (valueSize)
										{
										case sizeof (DBByte):  value = (DBInt) (*((DBByte *)  ((char *) dataRec->Data () + i * valueSize))); break;
										case sizeof (DBShort): value = (DBInt) (*((DBShort *) ((char *) dataRec->Data () + i * valueSize))); break;
										case sizeof (DBInt):	  value = (DBInt) (*((DBInt *)	((char *) dataRec->Data () + i * valueSize))); break;
										default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
										}
									break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Type in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							sprintf (nameStr,"Category%04d",value);
							if ((itemRec = itemTable->Item (nameStr)) == (DBObjRecord *) NULL)
								{
								if ((itemRec = itemTable->Add (nameStr)) == (DBObjRecord *) NULL)
									{ CMmsgPrint (CMmsgAppError, "Item Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
								gridValueFLD->Int (itemRec,value);
								gridSymbolFLD->Record (itemRec,symRec);
								}
							value = itemRec->RowID ();
							switch (valueSize)
								{
								case sizeof (DBByte):  *((DBByte *)  ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBShort): *((DBShort *) ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBInt):	  *((DBInt *)	 ((char *) dataRec->Data () + i * valueSize)) = value; break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							}
						}
					itemTable->ListSort (gridValueFLD);
					for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
						{
						for (i = 0;i < ColNum () * RowNum ();++i)
							{
							switch (valueSize)
								{
								case sizeof (DBByte):  value = (DBInt) (*((DBByte *)  ((char *) dataRec->Data () + i * valueSize))); break;
								case sizeof (DBShort): value = (DBInt) (*((DBShort *) ((char *) dataRec->Data () + i * valueSize))); break;
								case sizeof (DBInt):	  value = (DBInt) (*((DBInt *)	((char *) dataRec->Data () + i * valueSize))); break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							itemRec = itemTable->Item (value);
							value = itemRec->ListPos ();
							switch (valueSize)
								{
								case sizeof (DBByte):  *((DBByte *)  ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBShort): *((DBShort *) ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBInt):	  *((DBInt *)	 ((char *) dataRec->Data () + i * valueSize)) = value; break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							}
						}
					itemTable->ItemSort ();
					gridIF = new DBGridIF (data);
					gridIF->DiscreteStats ();
					delete gridIF;
					} break;
				case DBTypeGridContinuous:
					{
					DBObjTableField *missingValueFLD		= itemTable->Field (DBrNMissingValue);

					for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
						{
						itemTable->Add (dataRec->Name ());
						missingValueFLD->Float (itemTable->Item (),MissingValue ());
						}
					gridIF = new DBGridIF (data);
					gridIF->RecalcStats ();
					delete gridIF;
					data->Flags (DBDataFlagDispModeContBlueRed,DBSet);
					break;
					}
				default: break;
				}
			return (DBSuccess);
			}
UIListCell *MaterialEditor::CellAtIndex(UIList *forList, int32 index)
{
    UIListCell *c = forList->GetReusableCell("Material name cell");
    if (!c) 
    {
        c = new UIListCell(Rect(0, 0, forList->GetRect().dx, 20), "Material name cell");

        float32 boxSize = 16;
        float32 y = (CellHeight(forList, index) - boxSize) / 2;
        float32 x = forList->GetRect().dx - boxSize;
        
        
        //Temporary fix for loading of UI Interface to avoid reloading of texrures to different formates.
        // 1. Reset default format before loading of UI
        // 2. Restore default format after loading of UI from stored settings.
        Texture::SetDefaultFileFormat(NOT_FILE);
        
        Rect r = Rect(x, y, boxSize, boxSize);
        UIControl *sceneFlagBox = new UIControl(r);
        sceneFlagBox->SetName("flagBox");
        sceneFlagBox->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_TO_RECT);
        sceneFlagBox->SetSprite("~res:/Gfx/UI/marker", 1);
        sceneFlagBox->SetInputEnabled(false);
        c->AddControl(sceneFlagBox);
        SafeRelease(sceneFlagBox);
        
        Texture::SetDefaultFileFormat((ImageFileFormat)EditorSettings::Instance()->GetTextureViewFileFormat());
    }

    Material *mat = GetMaterial(index);
    bool found = false;
    if(EDM_ALL == displayMode)
    {
        for (int32 i = 0; i < (int32)workingNodeMaterials.size(); ++i)
        {
            if(workingNodeMaterials[i] == mat)
            {
                found = true;
                break;
            }
        }
    }
    else
    {
        found = true;
    }
    
    ControlsFactory::CustomizeListCell(c, StringToWString(mat->GetName()), false);
    UIControl *sceneFlagBox = c->FindByName("flagBox");
    sceneFlagBox->SetVisible(found, false);
    
    if (index == selectedMaterial) 
    {
        c->SetSelected(true, false);
        lastSelection = c;
    }
    else
    {
        c->SetSelected(false, false);
    }
    
    return c;
}
示例#13
0
  // draw a ground-hugging sprite
  //
  Bucket * RenderGroundSprite( const Vector &origin, F32 radx, F32 rady, U32 clipFlags, F32 viewz, const Bitmap *texture, Color color, U32 blend, UVPair uv0, UVPair uv1, UVPair uv2, const GETHEIGHTPROCPTR getHeightProc, U16 sorting) // UVPair(0.0f,1.0f), UVPair(1.0f,1.0f), UVPair(1.0f,0.0f), GetHeight
  {
  #ifdef DOSTATISTICS
    Statistics::tempTris = 0;
  #endif

    clipFlags;
    viewz;

    if (texture)
    {
      uv0.u += texture->UVShiftWidth();
      uv0.v += texture->UVShiftHeight();
      uv1.u += texture->UVShiftWidth();
      uv1.v += texture->UVShiftHeight();
      uv2.u += texture->UVShiftWidth();
      uv2.v += texture->UVShiftHeight();
    }

 	  // set the primitive description
	  Vid::SetBucketPrimitiveDesc(PT_TRIANGLELIST, FVF_TLVERTEX,
		  DP_DONOTUPDATEEXTENTS | DP_DONOTLIGHT | DP_DONOTCLIP | RS_TEXCLAMP | blend);

	  // set the world transform matrix
	  Vid::SetWorldTransform(Matrix::I);

    // set material, texture, and force translucency
    Vid::SetBucketMaterial( Vid::defMaterial);
	  Vid::SetBucketTexture( texture, TRUE, 0, RS_TEXCLAMP | blend);
//	  Vid::SetTranBucketZ(viewz);
    Vid::SetTranBucketZMax( sorting);

	  // sprite corners in world coordinates
	  F32 meterX0 = origin.x - radx + OffsetX();
	  F32 meterZ0 = origin.z - rady + OffsetZ();
    F32 meterX1 = origin.x + radx + OffsetX();
	  F32 meterZ1 = origin.z + rady + OffsetZ();

	  // get corners of the grid covered by the sprite
    // get grid larger than sprite; adjust texture coords
    // round down to grid point
    // round up to grid point

    U16 cw = Utils::FP::SetRoundDownMode();
	  S32 cellX0 = Utils::FastFtoL( meterX0 * CellPerMeter());
	  S32 cellZ0 = Utils::FastFtoL( meterZ0 * CellPerMeter());

    Utils::FP::SetRoundUpMode();
	  S32 cellX1 = Utils::FastFtoL( meterX1 * CellPerMeter());
	  S32 cellZ1 = Utils::FastFtoL( meterZ1 * CellPerMeter());

    Utils::FP::RestoreMode( cw);

	  // dimensions of sprite in grid squares
	  S32 sizex = (cellX1 - cellX0 + 1);
	  S32 sizez = (cellZ1 - cellZ0 + 1);
    if (U32(sizex * sizez + 1) >= Vid::renderState.maxVerts || U32(sizex * sizez * 6) >= Vid::renderState.maxIndices)     // FIXME
    {
      LOG_WARN( ("Shadow too big") );
      return NULL;
    }
#if 0
    // verify buffer size
    ASSERT();
#endif

	  // lock primitive memory
    VertexTL * vertmem;
    U16 * indexmem;
    U32 heapSize = Vid::Heap::ReqVertex( &vertmem, &indexmem);

    VertexTL * pvert = vertmem;
    U16 * pindex = indexmem;

    // delta meters per grid
	  F32 dm = (F32) MeterPerCell();

	  F32 dx12 = meterX0 - meterX0;
	  F32 dx02 = meterX0 - meterX1;
    F32 dz12 = meterZ0 - meterZ1;
	  F32 dz02 = meterZ0 - meterZ1;
	  F32 dx = dx12 * dz02 - dx02 * dz12;
	  if (dx == 0.0f)
    {
      dx = F32_EPSILON;
    }
	  dx = 1.0f / dx;
	  F32 dz = -dx;

    // delta texture coords
	  F32 du12 = (F32) (uv1.u - uv2.u);
	  F32 du02 = (F32) (uv0.u - uv2.u);
	  F32 dudx = (du12 * dz02 - du02 * dz12) * dx;
	  F32 dudz = (du12 * dx02 - du02 * dx12) * dz;

	  F32 dv12 = (F32) (uv1.v - uv2.v);
	  F32 dv02 = (F32) (uv0.v - uv2.v);
	  F32 dvdx = (dv12 * dz02 - dv02 * dz12) * dx;
	  F32 dvdz = (dv12 * dx02 - dv02 * dx12) * dz;

	  // texture coordinates of southwest grid point
    dx = (cellX0 * dm - meterX0);
    dz = (cellZ0 * dm - meterZ0);
    F32 u = uv0.u + dx * dudx + dz * dudz;
	  F32 v = uv0.v + dx * dvdx + dz * dvdz;

	  // texture coordinate delta per grid
	  dudx *= dm;
	  dvdx *= dm;
	  dudz *= dm;
	  dvdz *= dm;

	  // sprite grid corners in world coordinates
	  meterX0 = cellX0 * dm - OffsetX();
	  meterZ0 = cellZ0 * dm - OffsetZ();
    meterX1 = cellX1 * dm - OffsetX();
	  meterZ1 = cellZ1 * dm - OffsetZ();

    // generate vertices on grid cell points
    S32 cellX, cellZ;
	  for (cellZ = cellZ0; cellZ <= cellZ1; cellZ++, meterZ0 += dm, u += dudz, v += dvdz)
	  {
      F32 xx = meterX0;
      F32 uu = u;
      F32 vv = v;

		  for (cellX = cellX0; cellX <= cellX1; cellX++, xx += dm, uu += dudx, vv += dvdx)
		  {
        // allow cells at Width and Height
        //
        if (cellX < 0 || cellX > (S32)CellWidth() || cellZ < 0 || cellZ > (S32)CellHeight())
        {
          pvert++;
          continue;
        }
			  pvert->vv.x     = xx;
        pvert->vv.y     = (*getHeightProc)( cellX, cellZ);
			  pvert->vv.z     = meterZ0;
			  pvert->diffuse  = color;
			  pvert->specular = RGBA_MAKE(0x00, 0x00, 0x00, 0xFF);
			  pvert->u        = uu;
			  pvert->v        = vv;
			  pvert++;
		  }
    }

	  // generate indices
	  U32 offset = 0;

    U32 sizex1 = sizex + 1;

	  for (cellZ = cellZ0; cellZ < cellZ1; cellZ++)
	  {
		  for (cellX = cellX0; cellX < cellX1; cellX++)
		  {
        if (cellX < 0 || cellX >= (S32)CellWidth() || cellZ < 0 || cellZ >= (S32)CellHeight())
        {
          // cell off map
          offset++;
          continue;
        }
			  // upper left triangle
			  *pindex++ = (U16) offset;
			  *pindex++ = (U16)(offset + sizex);
			  *pindex++ = (U16)(offset + sizex1);

			  // lower right triangle
			  *pindex++ = (U16) offset;
			  *pindex++ = (U16)(offset + sizex1);
			  *pindex++ = (U16)(offset + 1);

			  // advance the base offset
			  offset++;
      }
		  // advance the base offset
		  offset++;
    }

    Bucket * bucket = NULL;
    // submit for projection and clipping
  #if 0
    if (clipFlags == clipNONE)
    {
      bucket = Vid::CurCamera().ProjectNoClipBias( NULL, vertmem, pvert - vertmem, indexmem, pindex - indexmem);
    }
    else
  #endif
    {
      bucket = Vid::ProjectClip( vertmem, pvert - vertmem, indexmem, pindex - indexmem);
    }

    Vid::Heap::Restore( heapSize);

  #ifdef DOSTATISTICS
    Statistics::groundSpriteTris = Statistics::groundSpriteTris + Statistics::tempTris;
  #endif

    return bucket;
  }