Closed Frankr0 closed 4 years ago
Thank you for your post. I am so busy this month. so wait a while please.
Thanks for your contributions.
After fews trying, I still can not find a solution. Please help. According to MSDN, "A DrawingContext must be closed before its content can be rendered".
I use that trick make window show something, is this a good way to show a chem object?
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
dc.Close();
drawingContext.DrawDrawing(dg);
dc = dg.Open();
drawVisitor = new WPFDrawVisitor(dc);
}
And how to highlight a atom? thx @kazuyaujihara
Use atom.SetProperty(StandardGenerator.HighlightColorKey, colorValue)
to highlight atoms.
thx!
The highlight will not work until I set it manually, default value seems not work well.
renderer.GetRenderer2DModel().SetHighlighting(HighlightStyle.OuterGlow);
Why the charge show like this? It seems flip vertically.
myMol = new AtomContainer();
myMol.Add(new Atom("C", new Vector2(1, 1)));
myMol.Add(new Atom("C", new Vector2(100, 100)));
myMol.AddBond(myMol.Atoms[0], myMol.Atoms[1], BondOrder.Single);
myMol.Add(new Atom("N", new Vector2(-100, 200)));
myMol.AddBond(myMol.Atoms[1], myMol.Atoms[2], BondOrder.Double);
myMol.Atoms[0].FormalCharge = 2;
@kazuyaujihara
Geomeric System is opposite between Java and WPF. Current porting is only for DepictionGenerator.
Very thanks!
How can I get the coordinates of mouse position if I use a Depiction
instead of a AtomContainerRenderer
?
I do it like this before:
Point mousePos = renderer.ToModelCoordinates(e.GetPosition(this).X, e.GetPosition(this).Y);
And can I set the color of a specific atom to display? like:
atom.setColor(Color.Red);
Actually, I wanna know is there such a way to change a specific atom's font family, font size, color? @kazuyaujihara
Refer SVG generation code, ie NCDK.Display/Depict/SvgDrawVisitor.cs
. This code is embedding atom and bond information in id
argument of svg file. It is very ad hoc way, but we may do it.
Thanks for you reply!
The moleculeSetRenderer
in ChemModelRenderer
is not instantiated but used in Paint
, is this a bug?
public ChemModelRenderer(List<IGenerator<IAtomContainer>> generators, IList<IGenerator<IReaction>> reactionGenerators, IFontManager fontManager) : base(new RendererModel())
{
this.fontManager = fontManager;
reactionSetRenderer = new ReactionSetRenderer(rendererModel, generators, reactionGenerators, fontManager);
this.Setup();
}
public Rect Paint(IChemModel chemModel, IDrawVisitor drawVisitor)
{
...
...
if (moleculeSet != null && reactionSet != null)
{
...
ElementGroup diagram = new ElementGroup
{
reactionSetRenderer.GenerateDiagram(reactionSet),
HERE===> moleculeSetRenderer.GenerateDiagram(moleculeSet)
};
...
}
}
@kazuyaujihara
It looks bug!! Thanks.
Hello! The drawing of OralElement
in WPFDrawVisitor
seems not right, it seems should not to subtract the radius. @kazuyaujihara
private void Visit(OvalElement oval)
{
var radius = oval.Radius;
var diameter = oval.Radius * 2;
var center = oval.Coord;
if (oval.Fill)
{
this.dc.DrawEllipse(
GetBrush(oval.Color),
null,
HERE===> new WPF.Point(center.X - radius, center.Y - radius), diameter, diameter);
}
else
{
this.dc.DrawEllipse(
null,
GetPen(oval.Color, 1),
HERE===> new WPF.Point(center.X - radius, center.Y - radius), diameter, diameter);
}
}
And the multiplication of fromPoint * Scale(unit, distance)
in StandardBondGenerator.cs
should be addition?
internal IRenderingElement GenerateDashedBond(Vector2 fromPoint, Vector2 toPoint, double start, double end)
{
Vector2 unit = NewUnitVector(fromPoint, toPoint);
int nDashes = parameters.GetDashSection();
double step = Vector2.Distance(fromPoint, toPoint) / ((3 * nDashes) - 2);
ElementGroup group = new ElementGroup();
double distance = 0;
for (int i = 0; i < nDashes; i++)
{
// draw a full dash section
if (distance > start && distance + step < end)
{
HERE==> group.Add(NewLineElement(fromPoint * Scale(unit, distance),
Sum(fromPoint, Scale(unit, distance + step))));
}
Hi! the query of dictionary may cause a KeyNotFoundException in RingPlacer.cs
.
// Different ring sizes get different start angles to have visually
// correct placement
int ringSize = ring.RingSize;
startAngle = startAngles[ringSize]; <==HERE
Should it be replaced by TryGetValue
?
if(startAngles.TryGetValue(ringSize, out double angle))
startAngle = angle;
@kazuyaujihara
The operation of Transform.Value
will not change the value of Matrix:
Transform transform = new TranslateTransform(100, 100);
Matrix matrix = transform.Value;
transform.Value.Scale(2, 1);
transform.Value.Scale(1, 2);
transform.Value.Translate(20, 20);
Console.WriteLine(transform.Value);
// 1,0,0,1,100,100
matrix.Scale(2, 1);
matrix.Scale(1, 2);
matrix.Translate(20, 20);
Console.WriteLine(matrix);
// 2,0,0,2,220,220
So it may not get the desired result in AbstractRenderer.cs
:
protected virtual void Setup()
{
double scale = rendererModel.GetScale();
double zoom = rendererModel.GetZoomFactor();
// set the transform
try
{
transform = new TranslateTransform(drawCenter.X, drawCenter.Y);
HERE==> //transform.Value.Scale(1, -1); // Converts between CDK Y-up & Java2D Y-down coordinate-systems
HERE==> transform.Value.Scale(scale, scale);
HERE==> transform.Value.Scale(zoom, zoom);
HERE==> transform.Value.Translate(-this.modelCenter.X, -this.modelCenter.Y);
}
catch (NullReferenceException)
{
// one of the drawCenter or modelCenter points have not been set!
Console.Error.WriteLine($"null pointer when setting transform: drawCenter={drawCenter} scale={scale} zoom={zoom} modelCenter={modelCenter}");
}
}
I change it to the following code and the result seems correct:
Matrix matrix = new Matrix(1, 0, 0, 1, drawCenter.X, drawCenter.Y);
matrix.Scale(scale, scale);
matrix.Scale(zoom, zoom);
matrix.Translate(-this.modelCenter.X, -this.modelCenter.Y);
transform = Transform.Parse(matrix.ToString());
@Frankr0 Thank you for your contribution. Could you make patches to fix these bugs and make the PR?
ok, I will try it.
Is ncdk must use 4.61 or higher?
4.6.1 is too high for me.
@kazuyaujihara
Which version are you using?
The idealisation version maybe is 4.0.
NCDK is using IReadOnlyList interface, which is introduced in .NET Framework 4.5. So it is not compatible with .NET Framework 4.0.
I am trying to follow that page to create minimal implementation of a "molecule editor" by ncdk.
I don't know how to trans the Java code to C#.
At first, I wrote that code:
I found the
drawingVisual
will not update until I close theDrawingContext
byg2.Close()
. AndWPFDrawVisitor
complained can not finddc
whenDrawingContext
is closed.I use
DrawingGroup
instead ofDrawingVisual
now, but the window show nothing.So what should I do? Thx
The whole code is here: