mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-04-21 12:27:27 +03:00
First functional example, ADC an Framebuffer Test
This commit is contained in:
170
Software/sie_cg/block_editor/diagramscene.cpp
Normal file → Executable file
170
Software/sie_cg/block_editor/diagramscene.cpp
Normal file → Executable file
@@ -62,23 +62,12 @@ DiagramScene::DiagramScene(QMenu *itemMenu, MainWindow *ownerWindow,
|
||||
myCorners=0;
|
||||
|
||||
TitleText = new DiagramTextItem(0,0,1,0xFFF,255,"BLOCK NAME HERE not visible",
|
||||
QPointF(500,370));
|
||||
QPointF(500,420));
|
||||
TitleText->setZValue(1000);
|
||||
addItem(TitleText);
|
||||
|
||||
}
|
||||
|
||||
void DiagramScene::editorLostFocus(DiagramTextItem *item)
|
||||
{
|
||||
QTextCursor cursor = item->textCursor();
|
||||
cursor.clearSelection();
|
||||
item->setTextCursor(cursor);
|
||||
|
||||
if (item->toPlainText().isEmpty()) {
|
||||
removeItem(item);
|
||||
item->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramScene::drawBackground(QPainter *p, const QRectF &r)
|
||||
{
|
||||
p -> save();
|
||||
@@ -148,7 +137,7 @@ QString DiagramScene::createPrototype()
|
||||
functionPrototype += "char ";
|
||||
break;
|
||||
case 3:
|
||||
functionPrototype += "integer ";
|
||||
functionPrototype += "int ";
|
||||
break;
|
||||
case 4:
|
||||
functionPrototype += "double ";
|
||||
@@ -157,10 +146,10 @@ QString DiagramScene::createPrototype()
|
||||
functionPrototype += "float ";
|
||||
break;
|
||||
case 6:
|
||||
functionPrototype += "short ";
|
||||
functionPrototype += "short int ";
|
||||
break;
|
||||
case 7:
|
||||
functionPrototype += "long ";
|
||||
functionPrototype += "long int ";
|
||||
break;
|
||||
case 8:
|
||||
functionPrototype += "unsigned char ";
|
||||
@@ -169,10 +158,10 @@ QString DiagramScene::createPrototype()
|
||||
functionPrototype += "unsigned integer ";
|
||||
break;
|
||||
case 10:
|
||||
functionPrototype += "unsigned short ";
|
||||
functionPrototype += "unsigned short int ";
|
||||
break;
|
||||
case 11:
|
||||
functionPrototype += "unsigned long ";
|
||||
functionPrototype += "unsigned long int ";
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
@@ -189,34 +178,6 @@ QString DiagramScene::createPrototype()
|
||||
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
foreach (QGraphicsItem *item, this->items(mouseEvent->scenePos())) {
|
||||
if (item->type() == DiagramTextItem::Type) {
|
||||
if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()<256)
|
||||
{
|
||||
myOwnerWindow->statusBar->showMessage(
|
||||
qgraphicsitem_cast<DiagramTextItem *>(item)->toPlainText() +
|
||||
tr("\t : Input/Output text label -> {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}"));
|
||||
}
|
||||
else if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()==256)
|
||||
{
|
||||
myOwnerWindow->statusBar->showMessage(
|
||||
qgraphicsitem_cast<DiagramTextItem *>(item)->toPlainText() +
|
||||
tr("\t : Text label -> {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}"));
|
||||
}
|
||||
else if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()==257)
|
||||
{
|
||||
myOwnerWindow->statusBar->showMessage(
|
||||
qgraphicsitem_cast<DiagramTextItem *>(item)->toPlainText() +
|
||||
tr("\t : Editable text label -> {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
myOwnerWindow->updateProt();
|
||||
|
||||
QString Text;
|
||||
@@ -243,8 +204,6 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
if(addResult!=-1)
|
||||
{
|
||||
textItem->setZValue(1000.0);
|
||||
connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||
addItem(textItem);
|
||||
textItem->setTextID(addResult);
|
||||
}
|
||||
@@ -252,7 +211,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
delete(textItem);
|
||||
QMessageBox::warning(0,"Full","The block can only have "
|
||||
"255 text items");
|
||||
"255 labels/IOs.");
|
||||
}
|
||||
emit textInserted(textItem);
|
||||
break;
|
||||
@@ -301,8 +260,40 @@ void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
||||
line->setLine(newLine);
|
||||
}
|
||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||
QPointF mousePos = mouseEvent->scenePos();
|
||||
mousePos.setX(mousePos.x()-500);
|
||||
mousePos.setY(-(mousePos.y()-500));
|
||||
|
||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||
QString barMesg= QString("X[%1] Y[%2]").arg(QString::number(mousePos.x()))
|
||||
.arg(QString::number(mousePos.y()));
|
||||
|
||||
foreach (QGraphicsItem *item, this->items(mouseEvent->scenePos())) {
|
||||
if (item->type() == DiagramTextItem::Type) {
|
||||
if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()<256)
|
||||
{
|
||||
barMesg +=
|
||||
tr(" ** Over In/Out text label with {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}");
|
||||
}
|
||||
else if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()==256)
|
||||
{
|
||||
barMesg +=
|
||||
tr(" ** Over text label with {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}");
|
||||
}
|
||||
else if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()==257)
|
||||
{
|
||||
barMesg +=
|
||||
tr(" ** Over editable text label with {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}");
|
||||
}
|
||||
}
|
||||
}
|
||||
myOwnerWindow->statusBar->showMessage(barMesg);
|
||||
|
||||
}
|
||||
|
||||
@@ -351,9 +342,11 @@ QDomDocument DiagramScene::toXmlFormat()
|
||||
QDomComment initialComments=document.createComment(
|
||||
"File for SIE Code Generator. Custmos Blocks");
|
||||
document.appendChild(initialComments);
|
||||
|
||||
QDomElement diagram = document.createElement("CustomItem");
|
||||
diagram.setAttribute("BlockName",TitleText->toPlainText());
|
||||
document.appendChild(diagram);
|
||||
|
||||
//Lists of items
|
||||
QList<DiagramTextItem *> Items;
|
||||
QList<Arrow *> Arrows;
|
||||
@@ -368,7 +361,8 @@ QDomDocument DiagramScene::toXmlFormat()
|
||||
if(Arrows.count()>1) {printf("Something is wrong.\n"); fflush(stdout);}
|
||||
|
||||
//Create the XML structure
|
||||
diagram.appendChild(myPolygonPath->toXml(document));
|
||||
if(myPolygonPath!=0)
|
||||
diagram.appendChild(myPolygonPath->toXml(document));
|
||||
|
||||
QDomElement element;
|
||||
if(Items.count()>0)
|
||||
@@ -386,6 +380,26 @@ QDomDocument DiagramScene::toXmlFormat()
|
||||
diagram.appendChild(textItems);
|
||||
}
|
||||
|
||||
|
||||
//Add the code as CDATA sections
|
||||
//Order: Header Code, Init Code, Block Code and Extra Code.
|
||||
|
||||
QDomCDATASection headerCode=document.createCDATASection(
|
||||
myOwnerWindow->headerTextEdit->toPlainText());
|
||||
diagram.appendChild(headerCode);
|
||||
|
||||
QDomCDATASection initCode=document.createCDATASection(
|
||||
myOwnerWindow->initTextEdit->toPlainText());
|
||||
diagram.appendChild(initCode);
|
||||
|
||||
QDomCDATASection blockCode=document.createCDATASection(
|
||||
myOwnerWindow->blockTextEdit->toPlainText());
|
||||
diagram.appendChild(blockCode);
|
||||
|
||||
QDomCDATASection extraCode=document.createCDATASection(
|
||||
myOwnerWindow->extraTextEdit->toPlainText());
|
||||
diagram.appendChild(extraCode);
|
||||
|
||||
return(document);
|
||||
}
|
||||
|
||||
@@ -401,11 +415,39 @@ int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||
TitleText->setPlainText("Please set Block Name");
|
||||
else
|
||||
TitleText->setPlainText(customItem.attribute("BlockName"));
|
||||
|
||||
TitleText->updatePosition();
|
||||
int codeIdx = 0;
|
||||
|
||||
for (QDomNode node = customItem.firstChild() ;
|
||||
!node.isNull() ;
|
||||
node = node.nextSibling())
|
||||
{
|
||||
{
|
||||
if(node.isCDATASection())
|
||||
{
|
||||
QDomCDATASection Code = node.toCDATASection();
|
||||
switch(codeIdx)
|
||||
{
|
||||
case 0:
|
||||
myOwnerWindow->headerTextEdit->setPlainText(Code.data());
|
||||
break;
|
||||
case 1:
|
||||
myOwnerWindow->initTextEdit->setPlainText(Code.data());
|
||||
break;
|
||||
case 2:
|
||||
myOwnerWindow->blockTextEdit->setPlainText(Code.data());
|
||||
break;
|
||||
case 3:
|
||||
myOwnerWindow->extraTextEdit->setPlainText(Code.data());
|
||||
break;
|
||||
default:
|
||||
QMessageBox::warning(0,"Parsing XML", tr("Extra CDATA found in")
|
||||
+tr(" file, this section will be ignored."));
|
||||
}
|
||||
codeIdx++;
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement element = node.toElement();
|
||||
if(element.tagName()=="Polygon")
|
||||
{
|
||||
@@ -446,6 +488,7 @@ int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||
|
||||
int myStyleIO = textItemE.attribute("myStyleIO").toInt();
|
||||
int myID = textItemE.attribute("ID").toInt();
|
||||
|
||||
bool editableItem = textItemE.attribute("editableItem").toInt();
|
||||
QPointF posOffset=
|
||||
QPointF((QPointF(textItemE.attribute("posOffset-x")
|
||||
@@ -465,12 +508,23 @@ int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||
DiagramTextItem * newTextItem =
|
||||
new DiagramTextItem(0,0,1,myStyleIO,myID,itemString,posOffset);
|
||||
newTextItem->setZValue(1000.0);
|
||||
connect(newTextItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||
addItem(newTextItem);
|
||||
textItemsByID.insert(myID,newTextItem);
|
||||
|
||||
if(textItemsByID.find(myID)!=textItemsByID.end())
|
||||
{
|
||||
int result=addTextItem(newTextItem);
|
||||
QMessageBox::warning(0,"ID Problems",
|
||||
tr("Label with ID[")+QString::number(myID)+
|
||||
tr("] already exists, this will be reasigned to [")+
|
||||
QString::number(result)+
|
||||
tr("] for prevent problems."));
|
||||
newTextItem->setTextID(result);
|
||||
}
|
||||
else
|
||||
textItemsByID.insert(myID,newTextItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
myOwnerWindow->updateProt();
|
||||
return 1;
|
||||
@@ -501,13 +555,15 @@ void DiagramScene::cleanScene()
|
||||
removeItem(myPolygonPath);
|
||||
delete(myPolygonPath);
|
||||
}
|
||||
TitleText->setPlainText("BLOCK NAME HERE (not visible)");
|
||||
TitleText->setPlainText("BLOCK NAME HERE not visible");
|
||||
TitleText->updatePosition();
|
||||
this->addItem(TitleText);
|
||||
textItemsByID.clear();
|
||||
}
|
||||
|
||||
int DiagramScene::addTextItem(DiagramTextItem * textItem)
|
||||
{
|
||||
for(int i=0; i<255; i++)
|
||||
for(int i=0; i<256; i++)
|
||||
{
|
||||
QHash<int,DiagramTextItem *>::iterator iter= textItemsByID.find(i);
|
||||
if(iter==textItemsByID.end())
|
||||
|
||||
Reference in New Issue
Block a user