| 523 | ==== Inserting and Updating Features with Annotation Properties ==== |
| 524 | |
| 525 | Annotation Text associated to FDO features will be insertable and updatable through a extended set of derived FDO interfaces that follow the existing !PropertyValue pattern used to specify data values for the FdoIInsert and FdoIUpadte comands. The newly defined Annotation interfaces will be derived from FdoExpression and FdoValueExpression and allow the Annotation properties to be set as Property Values and be parsed as expressions. |
| 526 | |
| 527 | The first step required to support an insertable Annotation is to derive a new !FdoAnnotationValue class from !FdoValueExpression. Instances of !FdoAnnotationValue will be set as the Value object on !FdoPropertyValue. Users of !AnnotationValue will have the ability to specify the Annotation Envelope and set of !TextElementValues attached to the Annotation. |
| 528 | |
| 529 | {{{ |
| 530 | class FdoAnnotationValue : public FdoValueExpression |
| 531 | { |
| 532 | public: |
| 533 | FdoGeometryValue* Envelope; |
| 534 | FdoStringValue* DefaultTextValue; |
| 535 | FdoStringValue* DefaultTextAttributesValue; |
| 536 | FdoAnnotationTextElementValueCollection* TextElementValues; |
| 537 | |
| 538 | public: |
| 539 | bool IsNull(); |
| 540 | void SetNullValue(); |
| 541 | void Process(FdoIExpressionProcessor* p); |
| 542 | FdoString* ToString(); |
| 543 | FdoExpressionItemType GetExpressionType(); |
| 544 | }; |
| 545 | }}} |
| 546 | |
| 547 | While the above class allows users to specify high level Annotation values, they will still need a secondary Expression interface to specify the order list of !TextElementValues attached to the Annotation. Through this interface, users will be able to specify the Annotation Text location, leader line, text value, and attributes. |
| 548 | |
| 549 | {{{ |
| 550 | class FdoAnnotationTextElementValue : public FdoExpression |
| 551 | { |
| 552 | public: |
| 553 | FdoGeometryValue* Location; |
| 554 | FdoGeometryValue* LeaderLine; |
| 555 | FdoStringValue* TextValue; |
| 556 | FdoStringValue* TextAttributesValue; |
| 557 | |
| 558 | public: |
| 559 | void Process(FdoIExpressionProcessor* p); |
| 560 | FdoString* ToString(); |
| 561 | FdoExpressionItemType GetExpressionType(); |
| 562 | }; |
| 563 | }}} |
| 564 | |
| 565 | ===== Inserting Features with Annotation Properties ===== |
| 566 | |
| 567 | Using the above Road/!RoadAnnotation Example, here is an example of how Annotation properties would be inserted into an FDO data store as a part of a feature. |
| 568 | |
| 569 | |
| 570 | {{{ |
| 571 | // Create an Insert command to create a Road |
| 572 | FdoPtr<FdoIInsert> insCmd = (FdoIInsert*)(conn->CreateCommand(FdoCommandType_Insert)); |
| 573 | insCmd->SetFeatureClassName(L"Road"); |
| 574 | FdoPtr<FdoPropertyValueCollection> propVals = insCmd->GetPropertyValues(); |
| 575 | |
| 576 | // Specify Road object's Geometry as a line string |
| 577 | FdoPtr<FdoDirectPositionCollection> objPoints = FdoDirectPositionCollection::Create(); |
| 578 | FdoPtr<FdoIDirectPosition> pt1 = gf->CreatePositionXY(pt_A.x, pt_A.y); |
| 579 | FdoPtr<FdoIDirectPosition> pt2 = gf->CreatePositionXY(pt_C.x, pt_B.y); |
| 580 | FdoPtr<FdoIDirectPosition> pt3 = gf->CreatePositionXY(pt_C.x, pt_C.y); |
| 581 | objPoints->Add(pt1); |
| 582 | objPoints->Add(pt2); |
| 583 | objPoints->Add(pt3); |
| 584 | FdoPtr<FdoILineStringSegment> lineSeg = gf->CreateLineStringSegment(objPoints); |
| 585 | FdoPtr<FdoByteArray> fgf = gf->GetFgf(lineSeg); |
| 586 | FdoPtr<FdoGeometryValue> gv = FdoGeometryValue::Create(fgf); |
| 587 | FdoPtr<FdoPropertyValue> propGeom = FdoPropertyValue::Create(L"Geometry", gv); |
| 588 | propVals->Add(propGeom); |
| 589 | |
| 590 | |
| 591 | // Specify Road object's Name |
| 592 | FdoPtr<FdoStringValue> strValue = FdoStringValue::Create(L"Main St."); |
| 593 | FdoPtr<FdoPropertyValue> propName = FdoPropertyValue::Create(L"Name", strValue); |
| 594 | propVals->Add(propName); |
| 595 | |
| 596 | // Specify Road object's Width |
| 597 | FdoPtr<FdoInt32Value> width = FdoInt64Value::Create(20); |
| 598 | FdoPtr<FdoPropertyValue> propWidth = FdoPropertyValue::Create(L"Width", width); |
| 599 | propVals->Add(propWidth); |
| 600 | |
| 601 | // Create a Text Annotation Location as a point in space |
| 602 | double* ordsXY = new double[2]; |
| 603 | ordsXY[0] = pt_D.x; ordsXY[1] = pt_D.y; |
| 604 | FdoPtr<FdoIGeometry> pnt = gf->CreatePoint(FdoDimensionality_XY, ordsXY); |
| 605 | FdoPtr<FdoByteArray> fgf2 = gf->GetFgf(pnt); |
| 606 | FdoPtr<FdoGeometryValue> gv2 = FdoGeometryValue::Create(fgf2); |
| 607 | |
| 608 | // Create a Text Annotation Leader Line as a 2 segment line |
| 609 | FdoPtr<FdoDirectPositionCollection> leaderPoints = FdoDirectPositionCollection::Create(); |
| 610 | FdoPtr<FdoIDirectPosition> pt4 = gf->CreatePositionXY(pt_E.x, pt_E.y); |
| 611 | FdoPtr<FdoIDirectPosition> pt5 = gf->CreatePositionXY(pt_F.x, pt_F.y); |
| 612 | FdoPtr<FdoIDirectPosition> pt6 = gf->CreatePositionXY(pt_G.x, pt_G.y); |
| 613 | leaderPoints->Add(pt4); |
| 614 | leaderPoints->Add(pt5); |
| 615 | leaderPoints->Add(pt6); |
| 616 | FdoPtr<FdoILineStringSegment> lineSeg2 = gf->CreateLineStringSegment(leaderPoints); |
| 617 | FdoPtr<FdoByteArray> fgf3 = gf->GetFgf(lineSeg2); |
| 618 | FdoPtr<FdoGeometryValue> gv3 = FdoGeometryValue::Create(fgf3); |
| 619 | |
| 620 | // Define the Annotation Text Envelope as a simple bounding box |
| 621 | FdoPtr<FdoIEnvelope> envl = gf->CreateEnvelopeXY(pt_H.x, pt_H.y, pt_J.x, pt_J.y); |
| 622 | FdoPtr<FdoByteArray> fgf4 = gf->GetFgf(envl); |
| 623 | FdoPtr<FdoGeometryValue> gv4 = FdoGeometryValue::Create(fgf4); |
| 624 | |
| 625 | // Specify the Annotation Text as an expression. Value determined at runtime |
| 626 | FdoPtr<FdoStringValue> textStrValue = FdoStringValue::Create(L"Road.Name"); |
| 627 | |
| 628 | // Specify the Annotation Text as an expression (NULL) |
| 629 | FdoPtr<FdoStringValue> textAttribValue = FdoStringValue::Create(L""); |
| 630 | textAttribValue->SetNull(); |
| 631 | |
| 632 | // Create the Text Element Values (only one here) associated to the annotation |
| 633 | FdoPtr<FdoAnnotationTextElementValue> eValue = FdoAnnotationTextElementValue::Create(); |
| 634 | eValue->SetLocation(gv2); |
| 635 | eValue->SetLeaderLine(gv3); |
| 636 | eValue->SetTextValue(textStrValue); |
| 637 | eValue->SetTextAttributesValue(textAttribValue); |
| 638 | |
| 639 | // Create the Annotation Value and set the Envelope and text elements |
| 640 | FdoPtr<FdoAnnotationValue> annValue = FdoAnnotationValue::Create(); |
| 641 | annValue->SetEnvelope(gv4); |
| 642 | FdoAnnotationTextElementValueCollectionP textElements = annValue->GetTextElementValues(); |
| 643 | textElements->Add(eValue); |
| 644 | FdoPtr<FdoPropertyValue> propAnn = FdoPropertyValue::Create(L"Annotation", annValue); |
| 645 | propVals->Add(propAnn); |
| 646 | |
| 647 | // Execute the insert |
| 648 | FdoPtr<FdoIFeatureReader> rdr = insCmd->Execute(); |
| 649 | }}} |
| 650 | |
| 651 | ===== Updating Features with Annotation Properties ===== |
| 652 | |
| 653 | Using the above Road/!RoadAnnotation Example, here is an example of how Annotation properties would be updated in an FDO data store as a part of a feature edit. |
| 654 | |
| 655 | |
| 656 | {{{ |
| 657 | // Create an Update command to create a Road |
| 658 | FdoPtr<FdoIUpdate> cmd = (FdoIUpdate*)(conn->CreateCommand(FdoCommandType_Insert)); |
| 659 | cmd->SetFeatureClassName(L"Road"); |
| 660 | FdoPtr<FdoPropertyValueCollection> propVals = cmd->GetPropertyValues(); |
| 661 | |
| 662 | // Specify the Filter |
| 663 | FdoPtr<FdoFilter> filter = FdoFilter::Parse(L"FeatId=100"); |
| 664 | cmd->SetFilter(filter); |
| 665 | |
| 666 | // Create a Text Annotation Location as a point in space |
| 667 | double* ordsXY = new double[2]; |
| 668 | ordsXY[0] = pt_D.x; ordsXY[1] = pt_D.y; |
| 669 | FdoPtr<FdoIGeometry> pnt = gf->CreatePoint(FdoDimensionality_XY, ordsXY); |
| 670 | FdoPtr<FdoByteArray> fgf2 = gf->GetFgf(pnt); |
| 671 | FdoPtr<FdoGeometryValue> gv2 = FdoGeometryValue::Create(fgf2); |
| 672 | |
| 673 | // Create a Text Annotation Leader Line as a 2 segment line |
| 674 | FdoPtr<FdoDirectPositionCollection> ldrPts = FdoDirectPositionCollection::Create(); |
| 675 | FdoPtr<FdoIDirectPosition> pt4 = gf->CreatePositionXY(pt_E.x, pt_E.y); |
| 676 | FdoPtr<FdoIDirectPosition> pt5 = gf->CreatePositionXY(pt_F.x, pt_F.y); |
| 677 | FdoPtr<FdoIDirectPosition> pt6 = gf->CreatePositionXY(pt_G.x, pt_G.y); |
| 678 | ldrPts->Add(pt4); |
| 679 | ldrPts->Add(pt5); |
| 680 | ldrPts->Add(pt6); |
| 681 | FdoPtr<FdoILineStringSegment> lineSeg2 = gf->CreateLineStringSegment(ldrPts); |
| 682 | FdoPtr<FdoByteArray> fgf3 = gf->GetFgf(lineSeg2); |
| 683 | FdoPtr<FdoGeometryValue> gv3 = FdoGeometryValue::Create(fgf3); |
| 684 | |
| 685 | // Define the Annotation Text Envelope as a simple bounding box |
| 686 | FdoPtr<FdoIEnvelope> envl = gf->CreateEnvelopeXY(pt_H.x, pt_H.y, pt_J.x, pt_J.y); |
| 687 | FdoPtr<FdoByteArray> fgf4 = gf->GetFgf(envl); |
| 688 | FdoPtr<FdoGeometryValue> gv4 = FdoGeometryValue::Create(fgf4); |
| 689 | |
| 690 | // Specify the Annotation Text as an expression. Value determined at runtime |
| 691 | FdoPtr<FdoStringValue> textStrValue = FdoStringValue::Create(L"Main St."); |
| 692 | |
| 693 | // Specify the Annotation Text as an expression (NULL) |
| 694 | FdoStringP textAttributes = GetTextAttributesAsXMLDocument(); |
| 695 | FdoPtr<FdoStringValue> textAttribValue = FdoStringValue::Create(textAttributes); |
| 696 | |
| 697 | // Create the Text Element Values (only one here) associated to the annotation |
| 698 | FdoAnnotationTextElementValueP txtElemVal = FdoAnnotationTextElementValue::Create(); |
| 699 | txtElemVal->SetLocation(gv2); |
| 700 | txtElemVal->SetLeaderLine(gv3); |
| 701 | txtElemVal->SetTextValue(textStrValue); |
| 702 | txtElemVal->SetTextAttributesValue(textAttribValue); |
| 703 | |
| 704 | // Create the Annotation Value and set the Envelope and text elements |
| 705 | FdoPtr<FdoAnnotationValue> annotationValue = FdoAnnotationValue::Create(); |
| 706 | annotationValue->SetEnvelope(gv4); |
| 707 | FdoAnnotationTextElementValueCollectionP txtElems = annValue->GetTextElementValues(); |
| 708 | textElements->Add(textElementValue); |
| 709 | FdoPtr<FdoPropertyValue> propAnn = FdoPropertyValue::Create(L"Annotation", annValue); |
| 710 | propVals->Add(propAnn); |
| 711 | |
| 712 | // Execute the update |
| 713 | FdoPtr<FdoITransaction> tr = conn->BeginTransaction(); |
| 714 | FdoInt32 rez = cmd->Execute(); |
| 715 | tr->Commit(); |
| 716 | }}} |